WebCpxMonitor

Z HKfree wiki
Verze z 6. 2. 2006, 23:24, kterou vytvořil 10.107.12.194 (diskuse)
(rozdíl) ← Starší verze | zobrazit aktuální verzi (rozdíl) | Novější verze → (rozdíl)
Skočit na navigaci Skočit na vyhledávání

<perl>

  1. !/usr/bin/perl
  1. =============================================================
  2. Web Cpx Monitor
  3. Script to retrieve AP's WLAN statistics
  4. from Compex NetPassage WPE54AG
  5. Author: pavkriz@hkfree.org
  6. Configuration:

my $ip = '10.107.AA.BB'; my $psw = 'password';

  1. =============================================================

use LWP::UserAgent; use strict;

  1. if this script is running from as CGI
  2. (one can also call this script e.g. from PHP
  3. or some other frameworks and include output
  4. in the "templated" pages)

my $runFromCGI = $ENV{SERVER_SOFTWARE};

my $ua = LWP::UserAgent->new;

  1. 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);

  1. was http request/response sucessful?

if ( ! ($res->is_success)) {

   print "Error: ".$res->status_line;
   exit;

}

  1. page retrieved after login

my $afterLogin = $res->as_string;

  1. 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;

}

  1. ask for "WLAN Station List" page (in AP mode)

my $req = HTTP::Request->new(GET => "http://$ip/staList.htm"); my $res = $ua->request($req);

  1. get the page content

my $staList = $res->as_string;

  1. print $staList; # print content - debug only
  1. 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>