pavement

Set-ddns.pl router settings list

From FreeBSDwiki
(Difference between revisions)
Jump to: navigation, search
(Westech WireSpeed DualConnect Home DSL Gateway)
Line 82: Line 82:
  
  
== Generic WAN-hosted CGI script ==
+
== Generic WAN-hosted CGI scripts ==
 +
 
 +
If you aren't having any luck with parsing your router's output ''or'' getting php to work on your webserver, one of these might come in handy... one is in perl and produces exactly the same output as the php version; the other is a shell script that comes close enough to fit the parser.  You can place either on a CGI-enabled server at http://server.net/cgi-bin/ip.cgi or something very like it.
 +
 +
#!/usr/bin/perl
 +
 +
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 aren't having any luck with parsing your router's output ''or'' getting php to work on your webserver, this might come in handy... it's intended to be placed on a CGI-enabled server at http://server.net/cgi-bin/ip.cgi or something very like it; and it produces the same output as the ip.php version shown above.
 
  
 
  #!/bin/sh
 
  #!/bin/sh

Revision as of 13:38, 21 May 2006

Contents

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 = 'http://192.168.1.254/homeBS.htm';

$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: dynamic.domain.net for the default, cable.dynamic.domain.net
# for WAN1, and dsl.dynamic.domain.net 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, dynamic.domain.net, over to whichever side is still up if one of them fails.

$ROUTER_URL = '192.168.0.1/netstat.htm';
$ROUTER_USERNAME = 'admin';
$ROUTER_PASSWORD = 'password';

$HOST0 = 'dynamic.domain.net';
$HOST1 = 'cable.dynamic.domain.net';
$HOST2 = 'dsl.dynamic.domain.net';

$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 set-ddns.pl 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 PHP script method

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 PHP script on your webserver and using it to feed your WAN IP back to you. This particular script gives output in the same format as http://checkip.dyndns.org - so tools designed to work with it will work with this, and vice versa. The parse code for set-ddns.pl included after the script is the same as that in the article, but it's included anyway below the CGI version of this IP fetcher, just so nobody gets confused.

<html>
<head>
<?php $ip = $_SERVER['REMOTE_ADDR']; ?>
<title>http://server.net/ip.php: <?php echo $ip; ?></title>
</head>
<body>
<?php echo "Current IP Address: " . $ip; ?>
</body>
</html>


Generic WAN-hosted CGI scripts

If you aren't having any luck with parsing your router's output or getting php to work on your webserver, one of these might come in handy... one is in perl and produces exactly the same output as the php version; the other is a shell script that comes close enough to fit the parser. You can place either on a CGI-enabled server at http://server.net/cgi-bin/ip.cgi or something very like it.

#!/usr/bin/perl

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";


#!/bin/sh

cat <<EOF
Content-type:text/plain

Current IP Address: ${REMOTE_ADDR}
EOF


Generic parser for use with http://server.net/ip.php, http://server.net/cgi-bin/ip.cgi, or http://checkip.dyndns.org

$url_string = 'http://server.net/ip.php';
$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