in reply to Get IP address from my Asante Cable/DSL router
Parsing the output of the Asante should be similar too.
Modifications made :#!/usr/bin/perl -w ###################################################################### +## # Get External IP address of Netgear router ################################################# use strict; use warnings; use LWP::UserAgent; use Data::Dumper; #use HTML::TableContentParser; use Getopt::Long; my $host=""; my $user=""; my $password=""; my $addr = ""; my $port=80; my $Netgear_Page = "s_status.htm"; # Netgear Router status my $Linksys_Page = "Status_Router.asp"; my $result=GetOptions( "host=s" => \$host, "user=s" => \$user, "password=s" => \$password, "ipaddress=s" => \$addr, "port=i" => \$port ); my $ua=LWP::UserAgent -> new(); if ($host){ }else{ for (qx/ipconfig/){ m/^\s+Default Gateway\D+([\d|\.]+)/ and $host=$1 }; } barf_and_complain() unless ( $host and $user and $password ); my $host_settings=sprintf("%s:%d",$host,$port); my $url = sprintf("http://%s:%d/$Netgear_Page",$host,$port); my $req = HTTP::Request->new(GET => $url); $req->authorization_basic($user, $password); my $content = $ua->request($req)->as_string; ##print "----Content--\n$content-----\n"; while ($content=~m/<table.*?>(.+?)<\/table>/igs){ my $table = $1; ##print "----TABLE:$table\n\n"; $table =~m/<h\d>(.+?)<\/h\d>/igs and print "=====TABLEHEAD: $1\n"; for ("MAC Address", "IP Address", "Domain Name Server"){ $table =~m/<td.*?>$_.+?<\/td>\s*<td.*?>([\w|:|\.|<|>]+?)<\/td>/ and print "\t $_ $1\n"; } } sub barf_and_complain { printf "%s\n",qq( You must specify all options for this plugin to work: --host hostname or ip of router --user security user of router --ipaddress expected ip address --password login password for router the --port option is just that, an option and default +s to 80 ); exit(1); }
"For every complex problem, there is a simple answer ... and it is wrong." --H.L. Mencken
|
|---|