Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Dyndns.org Updating Client

by lithron (Chaplain)
on Nov 23, 2003 at 23:18 UTC ( #309380=sourcecode: print w/ replies, xml ) Need Help??

Category: Web stuff
Author/Contact Info Ryan Whitworth lithron@gmail.com
Description: 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";

Comment on Dyndns.org Updating Client
Download Code
Re: Dyndns.org Updating Client
by b10m (Vicar) on Nov 23, 2003 at 23:27 UTC
    If anyone cares to tell me how to change my call to nslookup to something more perl-ish (or more portable), I'd be glad to change it.

    Net::DNS is your friend in this matter :)

    --
    B10m
      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 didn't know this. The CPAN test page doesn't show passed, nor failed tests for cygwin of new(er) versions :(

        What about Net::Nslookup ?

        Update: sorry, but I don't have a Win32 system that I could use to test this on myself

        --
        B10m
Re: Dyndns.org Updating Client
by allolex (Curate) on Nov 24, 2003 at 00:58 UTC
      I like updatedd for its very simple interface, myself.

      Makeshifts last the longest.

Re: Dyndns.org Updating Client
by TheFluffyOne (Beadle) on Nov 24, 2003 at 19:42 UTC

    I tend to use:

    use Socket; if ($ip = gethostbyname($domain)) { $ip = inet_ntoa($ip); print "IP address is $ip\n"; } else { print "Could not resolve name.\n"; }

    Not amazing, but does the job :) I assume you're going out to "whatismyip.com" because the IP address you want is not the box you run the script on?

    Gordon.

      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 :-)

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://309380]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-08-23 04:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls