Hello There, Guest!
View New Posts  |  View Today's Posts
[Perl] SysInfo Script - Created by Ace

  • 0 Vote(s) - 0 Average


08-22-2011, 02:27 PM #1
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

SysInfo Script - Created by Ace
Here's one of my most recent scripts using the Win32::Registry module to read values and data from the registry for stored information provided for the current status of your system including Windows install information.




Code:
#!/usr/bin/perl
use Win32::Registry;

$sublocation = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
$main::HKEY_LOCAL_MACHINE->Open($sublocation, $null) || die "Open: $!"; $null->GetValues(\%ID);

print "\n\            #--Ace\'s Basic SysInfo Script--\#\n";
print "\n------------------\\System Information\\------------------\n\n";
foreach $key_ (keys %ID) {
    if ($key_ eq "RegisteredOwner") {
        $entry = $ID{$key_};
        print "$$entry[0] = $$entry[2]\n";
    } elsif ($key_ eq "ProductId") {
        $entry = $ID{$key_};
        print "$$entry[0] = $$entry[2]\n";
    } elsif ($key_ eq "SystemRoot") {
        $entry = $ID{$key_};
        print "$$entry[0] = $$entry[2]\n";
    } elsif ($key_ eq "ProductName") {
        $entry = $ID{$key_};
        print "$$entry[0] = $$entry[2]\n";
    } elsif ($key_ eq "CSDVersion") {
        $entry = $ID{$key_};
        print "$$entry[0] = $$entry[2]\n";
    } elsif ($key_ eq "CurrentBuild") {
        $entry = $ID{$key_};
        print "$$entry[0] = $$entry[2]\n";
    }
}
print "\n--------------------------------------------------------\n\n";
This post was last modified: 08-22-2011, 02:28 PM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

10-05-2011, 12:56 AM #2
ordan
Junior Member
**
Posts: 12 Threads:0 Joined: Oct 2011 Reputation: 0

RE: SysInfo Script - Created by Ace
Nice example. Now I will write mine script.
Thank you

Do you have experience with HTML::Parser?!

10-05-2011, 01:36 AM #3
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: SysInfo Script - Created by Ace
Never used that module before, what are you trying to write?


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

10-05-2011, 02:00 AM #4
ordan
Junior Member
**
Posts: 12 Threads:0 Joined: Oct 2011 Reputation: 0

RE: SysInfo Script - Created by Ace
I want parse this page.

I want save file under text "Stream" and save alt-text.
I want this html tags: href, title

Thanks for helping

10-05-2011, 02:25 AM #5
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: SysInfo Script - Created by Ace
I'm trying my best to understand what you're trying to do here but as I can read what you're saying now i'm interpreting that you want to save a list of all of the links to a file (indicated by the html element "href"; meaning you want href="THIS") and also the text to be saved to the file from inside of the title html element (title="THIS"). Or both title and the alt html tags??
This post was last modified: 10-05-2011, 02:25 AM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

10-05-2011, 02:26 AM #6
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: SysInfo Script - Created by Ace
Edit: With regex it would be simple to parse the data out of the source but i'm still in the process of learning regex, I can only come up with basic regex match strings.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

10-05-2011, 03:19 AM #7
ordan
Junior Member
**
Posts: 12 Threads:0 Joined: Oct 2011 Reputation: 0

RE: SysInfo Script - Created by Ace
Yeah. It is simple. But what if it will not be on one line ;o(

I will try it.

I am advanced beginner in regexp ;o) I will share my work later.


10-05-2011, 04:01 AM #8
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: SysInfo Script - Created by Ace
Not be on one line? Not sure what you mean.

Here's my latest version of the script anyway, right now the decode subroutine is just there, but doesn't serve a purpose, it's a placeholder in case I find a way to use it for something later.

What this does is it will add separators, and add links line by line to an output file. Next time the script runs it will append onto the existing data within the file from before (hence why we need separators). The separators also display for which link the internalHTML data was derived from to make things easier.

Code:
use strict;
use warnings;
use LWP::Simple;

print "Processing links...\n\n";
my($url) = "http://hledani.rozhlas.cz/iradio/?p_po=317";
my($output) = get($url);

#In Progress - Decode to UTF8 subroutine
#Notes: Probably only needed if you're displaying output in the console.
&decode_utf8;
sub decode_utf8 {
    get("http://hledani.rozhlas.cz/iradio/?p_po=317");
}

# while ($output=~ m/href=\"(.*)\"/gi) {

open(F_HANDLE, ">>output_string.txt");
print F_HANDLE "<--- Start Of Output ($url) --->" . "\n\n";
while ($output=~ m/\"http(.*)\"/gi) {
    print F_HANDLE "http" . $1 . "\n";
}
print F_HANDLE "\n" . "<--- End Of Output ($url) --->" . "\n\n";
close (F_HANDLE);
exit;

This one I decided to experiment with a different regex modified by myself. This one uses matches for http and instead of using http:// because there MAY be a link (or may not) for https:// and it won't catch that if I specify the full thing. so it looks for http, displays the data AFTER it, and when we write to the file I add "http" to the beginning again so it's there on display. That way if it finds an http secure (https) link, it will parse data as s://www.somelink.somedomain, and when we add http to the beginning it will give the full link as https://www.somelink.somedomain.

LWP::Simple is the module we're using here to get the source of the webpage with the built in get() function. If you want to display directly pipelined to the console, the string of the full source output, you can use the getprint() function for that.

Instead of having to modify the script every time for a different link I can probably modify this for you as well to use input ARGS as a variable on input at interpret "runtime" or when the script first "loads" for the $url input.

Edit: Not sure what the heck is wrong with my regex script though. Some displays go past the " and into another HTML element, stopping at all sorts of different places.

I personally didn't like using /href=\"(.*)\"/ at all because you can get a link like href="#", and that's completely useless.
This post was last modified: 10-05-2011, 04:10 AM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

10-05-2011, 05:25 AM #9
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: SysInfo Script - Created by Ace
Agh! tried tons of regex codes that i've come up with and no success so far with getting just the link on some of the odd ones.

I've got it down to this one that i'm using currently for the link half:
Code:
m/\"*[http|https]:\/\/(.*)\"/gi

But i've also tried:
Code:
m/\"http:\/\/(.*)\"|\"https:\/\/(.*)\"/gi

And ton's others, but it all seems to be the same. Even with this it doesn't seem to accept anything, I get the same outputs everytime:
Code:
m/\"*[http|https]:\/\/(.*)[\"|\">]/gi

It doesn't want to stop the matching at " or "> for me it seems.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲

10-05-2011, 05:29 AM #10
ordan
Junior Member
**
Posts: 12 Threads:0 Joined: Oct 2011 Reputation: 0

RE: SysInfo Script - Created by Ace
It is what i needed.

Code:
m/stream"><a title="(.*)"\shref="(http[:\/a-zA-z0-9\.]+mp3)"\s+>Stream/ && print "Info: $1\nURL: $2\n";

I have problem with unicode but it is another story ;o)

Thank you for tip
(10-05-2011, 05:25 AM)Ace Wrote:  Agh! tried tons of regex codes that i've come up with and no success so far with getting just the link on some of the odd ones.

I've got it down to this one that i'm using currently for the link half:
[post=][/post]

But i've also tried:
[post=][/post]

And ton's others, but it all seems to be the same. Even with this it doesn't seem to accept anything, I get the same outputs everytime:
[post=][/post]

It doesn't want to stop the matching at " or "> for me it seems.

Your problem is asterix. it eats everything. you need string from html. It really long line ;o)
This post was last modified: 10-05-2011, 05:31 AM by ordan.




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
   TimeZone Check Script AceInfinity 6 4,003 11-23-2012, 08:53 PM
Last Post: AceInfinity
   Google Search Script (Text & Images, + History) AceInfinity 2 2,509 11-14-2012, 05:23 PM
Last Post: AceInfinity
   Batch Benchmarker Script AceInfinity 0 1,618 11-11-2012, 12:15 AM
Last Post: AceInfinity
   Nice Alert Batch Script - Task Scheduler AceInfinity 2 3,470 10-23-2012, 12:27 AM
Last Post: AceInfinity
   Typewriter Effect - Created by AceInfinity AceInfinity 2 4,400 02-21-2012, 09:39 PM
Last Post: AceInfinity


Users browsing this thread: 1 Guest(s)