01 #!/usr/local/bin/perl -w 02 use strict; 03 use Sysadm::Install qw(:all); 04 use WWW::Scripter; 05 use HTML::TableExtract; 06 use YAML qw(Dump); 07 08 my $w = new WWW::Scripter; 09 $w->use_plugin('Ajax'); 10 11 my $pw = slurp "pw.txt"; 12 chomp $pw; 13 14 $w->credentials( "root", $pw ); 15 $w->get( 16 'http://192.168.0.1/bwm-realtime.asp'); 17 18 rounds( $w, 5, sub { } ); 19 rounds( $w, 1, \&extract_bandwidth ); 20 21 ########################################### 22 sub rounds { 23 ########################################### 24 my( $w, $rounds, $callback ) = @_; 25 26 for( 1 .. $rounds ) { 27 $w->check_timers(); 28 sleep( 1 ); 29 } 30 31 $callback->( $w->content ); 32 } 33 34 ########################################### 35 sub extract_bandwidth { 36 ########################################### 37 my( $html ) = @_; 38 39 my $te = HTML::TableExtract->new( ); 40 $te->parse( $html ); 41 42 my $ts = $te->first_table_found(); 43 44 my %bw = (); 45 46 foreach my $row ($ts->rows) { 47 my @cols = map { /(\S+)/ } @$row; 48 49 $bw{ $cols[0] } = 50 { avg => $cols[3], 51 peak => $cols[5], 52 }; 53 } 54 55 print Dump( \%bw ); 56 }