Category: | Networking Code |
Author/Contact Info | Adam Monsen <adamm@wazamatta.com> http://adammonsen.com |
Description: | This script can get the external (WAN) IP assigned to a Linksys BEFSR41/BEFSR11/BEFSRU31 router using the Web interface provided by the router. The external IP is printed to standard output. requires WWW::Mechanize, HTML::Scrubber, HTML::Entities, and Regexp::Common. A good alternative to this script is simply fetching http://checkip.dyndns.org/ and parsing that result. |
#!/usr/bin/perl -w use strict; use WWW::Mechanize; use HTML::Scrubber; use HTML::Entities; use Regexp::Common qw(net); our $USER = 'admin'; our $PASS = 'secret'; my $mech = new WWW::Mechanize autocheck => 1; my $scrubber = new HTML::Scrubber; my $gateway_ip = '192.168.1.1:80'; $mech->credentials( $gateway_ip, 'Linksys BEFSR41/BEFSR11/BEFSRU31', $USER, $PASS); $mech->get("http://$gateway_ip/Status.htm"); my $content = $mech->content; my ($html) = ($content =~ /WAN head-->(.*?)<!--WAN tail/); $html = decode_entities($scrubber->scrub($html)); my ($ip) = ($html =~ /IP Address:($RE{net}{IPv4})/); $ip or die "IP not found."; print "$ip\n"; |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Get External IP From Linksys Router
by TimToady (Parson) on Apr 29, 2004 at 00:31 UTC | |
Re: Get External IP From Linksys Router
by Nkuvu (Priest) on Apr 28, 2004 at 23:43 UTC | |
by meonkeys (Chaplain) on Mar 10, 2015 at 21:11 UTC |