Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
PerlMonks 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
Description: A "smart" client that will update your (or other domain from the company) to your current IP address. Works from behind a NAT (via 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 = '';
my $mx = '';

my $ipaddress = LWP::Simple::get("");
if ($ipaddress =~ /([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})/) 
  $ipaddress = $1; 

my $nslookup = "";
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";

print "Updating the IP address ($ipaddress) now ... \n";

my $response = LWP::Simple::get("http://$login:$password\@" .
"$domain" .

print "Status : $response\n";

Replies are listed 'Best First'.
Re: 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: 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 :)

      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

Re: 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 "" because the IP address you want is not the box you run the script on?


      I like the code, and the concept. I'll change things when I get home and do an update. I use 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 :-)
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2019-12-05 22:00 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (152 votes). Check out past polls.