/[cricket]/parse_aphtml.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /parse_aphtml.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sat Aug 9 21:37:01 2003 UTC (15 years, 10 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/plain
added module to parse html output from TrendNet AP and draw packet count

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     # this module will fetch html page from AP and dump stats for LAN and WiFi
4     #
5     # it's for TrendNet AP with firmware 3.5.0, if you have different one, you
6     # might want to modify it.
7     #
8     # 2003-08-09 Dobrica Pavlinusic <dpavlin@rot13.org>
9    
10     use strict;
11     use WWW::Mechanize;
12    
13     # URL to your page (http or https)
14     my $uri = shift @ARGV || "https://192.168.95.254:8443/Status.htm";
15     my $user = shift @ARGV || "admin";
16     my $pass = shift @ARGV || "";
17    
18     # how to find data on your page this are case-INsensitive regexps for that
19     my $lan_regex = 'LAN.+?Send: (\d+).+?Receive: (\d+)';
20     my $wifi_regex = 'Wireless.+?Send: (\d+).+?Receive: (\d+)';
21    
22     {
23     package RequestAgent;
24     no strict 'vars';
25     @ISA = qw(WWW::Mechanize);
26    
27     sub new {
28     my $self = WWW::Mechanize::new(@_);
29     $self;
30     }
31    
32     sub get_basic_credentials {
33     return($user,$pass);
34     }
35     }
36    
37     my $mech = RequestAgent->new(
38     cookie_jar => undef
39     );
40    
41    
42     $mech->get( $uri );
43     $mech->success or die "Can't fetch $uri\n", $mech->res->status_line, "\n";
44    
45     $mech->is_html or die "$uri returns type \"", $mech->ct, "\", not \"text/html\"\n";
46    
47     # get content
48     my $txt = $mech->content; # get html
49     $txt =~ s#</*[^>]+>##g; # remove tags
50     $txt =~ s#&nbsp;# #g;
51     $txt =~ s#\s+# #g;
52    
53     #print "AP returned:\n$txt\n\n";
54    
55     if ($txt =~ m/$lan_regex/s) {
56     print "$1\n$2\n";
57     } else {
58     print "U\nU\n";
59     }
60    
61     if ($txt =~ m/$wifi_regex/s) {
62     print "$1\n$2\n";
63     } else {
64     print "U\nU\n";
65     }
66    

  ViewVC Help
Powered by ViewVC 1.1.26