#!/usr/bin/perl # # IP-UPDATE - Update Dynamic DNS # November 2000 # # Query the LinkSys router to determine the currently assigned DHCP # address. Then send an update to the Dynamic DNS server at JustLinux.com # if it's changed from the last time. # if ($ARGV[0] eq "-h") { print STDERR "Usage: ip-update.pl [-v | -h]\n"; exit; } # # JustLinux settings # $USER_ID="your_ID"; $PASSWORD="your_password"; $DNSID="your_dynsid"; # # Get current IP address # $_ = `lynx -dump http://192.168.1.1/Status.htm`; s/IP Address:/ip address/; # Skip first entry if (/IP Address: (.*)/) { $newip = $1; } else { print STDERR "Failure, couldn't get new IP address\n$_\n"; exit; } if ($ARGV[0] eq "-v") { print "Current IP address: $newip\n"; } # # Get old IP address # if (-e "/tmp/old-ip") { if (open(OLD,"/tmp/old-ip")) { $oldip = ; $oldip =~ tr/\n\r//d; close(OLD); if ($ARGV[0] eq "-v") { print "Previous IP address: $oldip\n"; } } else { print STDERR "Error: /tmp/old-ip exists, but I can't read from it: $!\n"; exit; } } else { if ($ARGV[0] eq "-v") { print "No previous IP address, updating.\n"; } } # # Compare and update # if (($oldip eq "") || ($newip ne $oldip)) { if (open(OLD,">/tmp/old-ip")) { print OLD $newip,"\n"; close(OLD); } else { print STDERR "Couldn't update /tmp/old-ip: $!\n"; } } # # Update DNS server # if ($oldip ne $newip) { $url1 = "-accept_all_cookies http://www.justlinux.com/bin/dologin?username=$USER_ID&password=$PASSWORD" ; `lynx -dump $url1`; # Get a cookie(?) if ($? == 0) { $url2 = "http://www.justlinux.com/bin/controlpanel/dyndns/update.pl?dnsid=$DNSID&ip=$newip&action=up date"; `lynx -dump $url2`; } if ($? != 0) { $rc = $? / 256; print STDERR "Return code: $rc from Lynx\n$s\n"; exit; } `logger IP-UPDATE: IP address changed to $newip... updating DNS`; if ($ARGV[0] eq "-v") { print "Updating 'justlinux'\n"; print "lynx -dump $url1\n"; print "lynx -dump $url2\n"; } }