A "smart" client that will update your Dyndns.org (or other domain from the company) to your current IP address. Works from behind a NAT (via www.whatismyip.com).
Only tested under Win32 with Cygnus' Cygwin tools installed. Requires LWP::Simple and Socket.
Updated : removed the call to nslookup thanks to code provided by TheFluffyOne
#!/usr/bin/perl -w
use strict;
use warnings;
use LWP::Simple;
use Socket;
my $login = 'test';
my $password = 'test';
my $domain = 'test.mine.nu';
my $mx = 'mail.test.mine.nu';
my $ipaddress = LWP::Simple::get("http://www.whatismyip.com");
if ($ipaddress =~ /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/)
{
$ipaddress = $1;
}
my $nslookup = "0.0.0.0";
if ($nslookup = gethostbyname($mx)) {
$nslookup = inet_ntoa($nslookup);
} else {
print "Could not resolve domain name, check $domain is correct\n";
print "Going to try to update information for $domain anyway ...\n";
}
if ($ipaddress eq $nslookup) {
print "Nothing to update. Current IP ($nslookup)";
print " = DNS address ($ipaddress)\n";
exit(0);
}
print "Updating the IP address ($ipaddress) now ... \n";
my $response = LWP::Simple::get("http://$login:$password\@" .
"members.dyndns.org/nic/update?system=dyndns&hostname=$domain" .
"&myip=$ipaddress&wildcard=ON&mx=$mx&backmx=NO&offline=NO");
print "Status : $response\n";
As you probably know, there are already a few dyndns clients out there, most (all?) of which are listed at https://www.dyndns.org/services/dyndns/clients.html. I like Paul Burry's ddclient (one of a number written in Perl) because it allows me to update the WAN IP my router is picking up.
Net::DNS doesn't seem to like my Cygwin Perl 5.8.1 install at home, nor my Cygwin 5.8.0 install at work :-( When I get a chance I'll file bug reports to the author.
Update:Perl 5.8.2 just got released for Cygwin, and Net::DNS works fine.. although I still prefer the solution given below. It doesn't require more modules, and I like that :-)
I like the code, and the concept. I'll change things when I get home and do an update.
I use whatismyip.com because the computer I run the code on is behind a NAT. Then I let the NAT forward ports to my internal computers. Plus, for those that don't have a NAT, it always retrieves the correct world routeable IP address, instead of grabbing the first network card's IP.
I believe the above code could easily replace my call to nslookup. Thank you so much :-)