pavement router settings list

From FreeBSDwiki
Jump to: navigation, search

This article contains a list of several methods of extracting and parsing your WAN IP address from various routers and externally hosted scripts, for use with, a script you can use to update a dynamic zone on a nameserver that you control.

If you have a router we haven't covered, and you adapt a method to extract its WAN IP, please feel free to add it here in a section headed by == Your Router's Model == bracketed with twin equals signs.


Westech WireSpeed DualConnect Home DSL Gateway

# BellSouth el cheapo residential gateway: there is no configurable username and password to set!
# Just make sure that either your WireSpeed is still set to the factory default private IP address,
# or that you adjust the router_url_string below to reflect whatever you have it set to now.

$router_url_string = '';

$ua = LWP::UserAgent->new;
$req = HTTP::Request->new('GET',$router_url_string);
$resp = $ua->request($req)->as_string();

@body = split (/\n/, $resp);
$WAN = ;
foreach $string (@body) {
    if ($WAN eq ) {
         if ($string =~ /^var IpAddress \= \"(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3})\"\;/) {
               $WAN = $1;

Xincom Twin Wan Router XC-DPG502

# This is a dual-homed router.  This code block assumes cable on WAN1 and dsl on WAN2, with a preference 
# for WAN1.  So three host records are kept: for the default,
# for WAN1, and for WAN2.  If you get fancy, you could even set something tricky 
# up on the server side to check WAN1 and WAN2 from the other side after they're established, and automatically 
# fail the "default" host,, over to whichever side is still up if one of them fails.

$ROUTER_PASSWORD = 'password';

$HOST0 = '';
$HOST1 = '';
$HOST2 = '';

$router_url_string = 'http://' . $ROUTER_USERNAME . ':' . $ROUTER_PASSWORD . '@' . $ROUTER_URL;
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new('GET',$router_url_string);
$resp = $ua->request($req)->as_string();

# Simplest to just count the dotted quads: WAN1 and WAN2 are the second and third one in.
$_ = $resp;
($ip1, $ip2, $ip3) = /\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}/gs;

$WAN1 = $ip2;
$WAN2 = $ip3;

# You don't want to cycle through for each host - it's MUCH slicker and quicker to send all
# three updates in a single nsupdate invocation.  Note: I chose to skip the "show" command on nsupdate here.
# It's handy for manual troubleshooting, but unnecessary once you have everything working and you're relying
# on a crontab piping the output to /dev/null anyway.

chdir ($KEYDIR);
open (NSUPDATE, "| /usr/sbin/nsupdate -k $KEYFILE");
print NSUPDATE "server $NAMESERVER\n";
print NSUPDATE "update delete $HOST0 A\n";
print NSUPDATE "update delete $HOST1 A\n";
print NSUPDATE "update delete $HOST2 A\n";
print NSUPDATE "update add $HOST0 $TTL A $WAN1\n";
print NSUPDATE "update add $HOST1 $TTL A $WAN1\n";
print NSUPDATE "update add $HOST2 $TTL A $WAN2\n";
print NSUPDATE "send\n";
close (NSUPDATE);

Generic WAN-hosted script methods

If you're having a particularly tough time trying to worm any useful information out of your router's regularly available configs, you can always fall back on hosting a script on your webserver and using it to feed your WAN IP back to you. You have three options here; a PHP script, a Perl-CGI, and a Bourne-CGI. Each of them give output in the same format as - so tools designed to work with it will work with these, and vice versa.

This php version can be run from any php-enabled directory on your server - depending on your php configuration, you may be able to run it as ip.html, or you might need to name it ip.php.

<?php $ip = $_SERVER['REMOTE_ADDR']; ?>
<title> <?php echo $ip; ?></title>
<?php echo "Current IP Address: " . $ip; ?>

If you aren't having any luck with parsing your router's output or getting php to work on your webserver, this perl-CGI version produces exactly the same output as the php version above. Place it in a cgi-enabled directory - on most servers, that will be or something very like it.


print "Content-type:text/html\n\n";
print "<html><head><title>$ENV{REMOTE_ADDR}</title></head>\n";
print "<body>Current IP Address: $ENV{REMOTE_ADDR}</body>\n";
print "</html>\n";

If you still aren't having any luck (or expect TONS of traffic and prefer a bit lower overhead), you can also try this Bourne scripted version - it's text-only, so no IP address in the page title, but the body output is identical to the other two so that the same parser still works.


cat <<EOF

Current IP Address: ${REMOTE_ADDR}

Generic parser for use with,, or

(Remember to change $url_string to match the script you're referencing.)

$url_string = '';
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new('GET',$url_string);
$resp = $ua->request($req)->as_string();

$_ = $resp;
m/.*?Current IP Address\: (\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}).*/gs;
$WAN = $1;

D-Link DGL-4300 802.11g MIMO "Gamer's Lounge" Router

# note: this sucker does fancy 'fake authentication' that uses some sort of session ID instead of
# standard HTTP authentication.  It's certainly possible to mimic it using LWP::Credentials, but I'm not 
# feeling the need to actually fight it through right now - and since it supports true syslog output, it might 
# be easier just to set up a syslog server and monitor incoming syslog messages for the latest incoming
# line to match /.*?IP Address (\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}) and default gateway/ and work from that.
# of course, since this is only a single WAN router, you could always take the cheesy route and just fall back
# on one of the external script methods outlined above. =)
Personal tools