# Ray Espinoza # GetAPC.pl # This script will take a list of ip addresses of APCs and # send the desired output to a textfile. ###################################################################### #!D:\perl\bin -w use LWP::UserAgent; use HTTP::Request; use HTML::TableExtract ##################################################################### # Asking for Output file names. ##################################################################### print "Enter the name of the output file:\n"; chomp($OutFile = ); ###################################################################### # Opens the outfile for appending ###################################################################### open(OUT,">$OutFile") || die "Can't create $OutFile: $!"; ###################################################################### # This will log into the apc and grab the html and stuff it into an # array and then i will take that array and add a new line to every # line and stuff that into a variable ####################################################################### $ua = new LWP::UserAgent; $url = 'http://192.168.1.1/pdumaina'; #print $url; $request = new HTTP::Request('GET',$url); $request->authorization_basic('login', 'password'); $ua->timeout(10); $response = $ua->request($request); $responsecode = $response->code(); if ($responsecode != 200) { print "Failed Request: $responsecode\n"; } else { # login successful, let's get the html code into a variable @ARRAY_OF_LINES = (split "\n", $ua->request($request)->as_string); foreach $line (@ARRAY_OF_LINES) { $html_code .= $line . "\n"; } } ######################################################################## # This will attempt to use HTML::TableExtract to look for these specific # headers in the html tables and print out the values in the table. ######################################################################## $te = new HTML::TableExtract( headers => [qw(Outlet Device Name)] ); $te->parse($html_code); print OUT $te; close(OUT) || warn "Couldn't close $OutFile";