WebCpxMonitor
Verze z 6. 2. 2006, 23:24, kterou vytvořil 10.107.12.194 (diskuse)
<perl>
- !/usr/bin/perl
- =============================================================
- Web Cpx Monitor
- Script to retrieve AP's WLAN statistics
- from Compex NetPassage WPE54AG
- Author: pavkriz@hkfree.org
- Configuration:
my $ip = '10.107.AA.BB'; my $psw = 'password';
- =============================================================
use LWP::UserAgent; use strict;
- if this script is running from as CGI
- (one can also call this script e.g. from PHP
- or some other frameworks and include output
- in the "templated" pages)
my $runFromCGI = $ENV{SERVER_SOFTWARE};
my $ua = LWP::UserAgent->new;
- try login to compex
my $req = HTTP::Request->new(POST => "http://$ip/act_login"); $req->content_type('application/x-www-form-urlencoded'); $req->content('Bcmd=20&PSW='.$psw);
my $res = $ua->request($req);
- was http request/response sucessful?
if ( ! ($res->is_success)) {
print "Error: ".$res->status_line; exit;
}
- page retrieved after login
my $afterLogin = $res->as_string;
- hadle common exceptions
if ($afterLogin =~ /WRONG PASSWORD/) {
print "Error: Wrong password"; exit;
}
if ($afterLogin =~ /the router is already being managed/) {
print "Error: Unable to open session, the router is already being managed"; exit;
}
- ask for "WLAN Station List" page (in AP mode)
my $req = HTTP::Request->new(GET => "http://$ip/staList.htm"); my $res = $ua->request($req);
- get the page content
my $staList = $res->as_string;
- print $staList; # print content - debug only
- parse table containing stations
if ($staList =~ /(
.+?<\/table>)/s) { my $onlyList = $1; # remove links $onlyList =~ s/<a href=(.+?)>//g; $onlyList =~ s/<\/a>//g; # print table to output print "Content-type: text/html\n\n<html><body>" if ($runFromCGI); print $onlyList; print "</body></html>" if ($runFromCGI); } else { print "Error: Unknown format"; } </perl>