Hi Everyone,
I'm very new to HTML source code and Perl scripts but I've been trying to get this script working to logon to my 3com ADSL router modem, goto the Status page and record certain stats (eg signal margin) into a text file.
I found this script on the net:
##### start code #####
# --- VARIABLES --- #
# url to stats page - replace user & pass with the router username & password
my $url ='
# output file
my $log = 'C:\Temp\router-stats.txt';
# --- PROGRAM --- #
# connect to router and get raw html
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $req = HTTP::Request->new(GET => $url);
my $response = $ua->request($req);
my $html = $response->content;
# get date/time & format
my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time());
my $dt = sprintf("%04d%02d%02d%02d%02d",1900+$year,$mon+1,$mday,$hour,$min);
# extract statistic
$html =~ s/(\s|\n)+//g;
my($stat) = $html =~ m!NoiseMargin</td><tdwidth=185class=textCell>[^&]+ dB</td><tdwidth=185class=textCell>([^&]+)!;
# print to file
open(FH,">>$log");
print FH "$dt $stat\n";
close(FH);
##### end code #####
The problem is the program doesn't seem to return anything from the web page (just the time as requested). I think it's because the source code its looking for doesn't match up with what the source code is (because this script was designed for a different modem). I've looked at the source code but am not knowledgable enough with HTML and Perl to know how to alter it. For example, from the source code below, I'd want to try and capture the "Noise Margin". Can anyone help?
Many thanks in advance.
RodP
***HTML source from stauts page from router***
<tr><td colspan=3 class=titleCell>Operation Data</td></tr>
<tr><td width=190 class=textCell>Operation Data</th>
<td width=190 class=textCell>Upstream</th>
<td width=190 class=textCell>Downstream</th></tr>
<tr><td width=190 class=textCell>Noise Margin</td>
<td width=185 class=textCell>-0.5 dB</td>
<td width=185 class=textCell>-0.5 dB</td></tr>
<tr><td width=190 class=textCell>Output Power</td>
<td width=185 class=textCell>-0.5 dBm</td>
<td width=185 class=textCell>-0.5 dBm</td></tr>
<tr><td width=190 class=textCell>Attenuation</td>
<td width=185 class=textCell>-0.5 dB</td>
<td width=185 class=textCell>-0.5 dB</td></tr>
I'm very new to HTML source code and Perl scripts but I've been trying to get this script working to logon to my 3com ADSL router modem, goto the Status page and record certain stats (eg signal margin) into a text file.
I found this script on the net:
##### start code #####
# --- VARIABLES --- #
# url to stats page - replace user & pass with the router username & password
my $url ='
# output file
my $log = 'C:\Temp\router-stats.txt';
# --- PROGRAM --- #
# connect to router and get raw html
use LWP::UserAgent;
my $ua = new LWP::UserAgent;
my $req = HTTP::Request->new(GET => $url);
my $response = $ua->request($req);
my $html = $response->content;
# get date/time & format
my ($sec, $min, $hour, $mday, $mon, $year) = localtime(time());
my $dt = sprintf("%04d%02d%02d%02d%02d",1900+$year,$mon+1,$mday,$hour,$min);
# extract statistic
$html =~ s/(\s|\n)+//g;
my($stat) = $html =~ m!NoiseMargin</td><tdwidth=185class=textCell>[^&]+ dB</td><tdwidth=185class=textCell>([^&]+)!;
# print to file
open(FH,">>$log");
print FH "$dt $stat\n";
close(FH);
##### end code #####
The problem is the program doesn't seem to return anything from the web page (just the time as requested). I think it's because the source code its looking for doesn't match up with what the source code is (because this script was designed for a different modem). I've looked at the source code but am not knowledgable enough with HTML and Perl to know how to alter it. For example, from the source code below, I'd want to try and capture the "Noise Margin". Can anyone help?
Many thanks in advance.
RodP
***HTML source from stauts page from router***
<tr><td colspan=3 class=titleCell>Operation Data</td></tr>
<tr><td width=190 class=textCell>Operation Data</th>
<td width=190 class=textCell>Upstream</th>
<td width=190 class=textCell>Downstream</th></tr>
<tr><td width=190 class=textCell>Noise Margin</td>
<td width=185 class=textCell>-0.5 dB</td>
<td width=185 class=textCell>-0.5 dB</td></tr>
<tr><td width=190 class=textCell>Output Power</td>
<td width=185 class=textCell>-0.5 dBm</td>
<td width=185 class=textCell>-0.5 dBm</td></tr>
<tr><td width=190 class=textCell>Attenuation</td>
<td width=185 class=textCell>-0.5 dB</td>
<td width=185 class=textCell>-0.5 dB</td></tr>