#!/usr/bin/perl use Net::Nslookup; # Set to 0 disable test mode. 1 enables test mode. IP will be 111.111.111.111 in test mode. $test = 0; # Host's (machine) name only. Do NOT include domainname. $host = "example"; # Host's domainname only. $domain = "myhost.com"; # As an example for above, if the FQDN (Fully Qualified DomainName) of this machine was "example.myhost.com", $host should be set to "example" and $domain should be set to "myhost.com". # Set to master nameserver listed for $domain. $master_nsserver = "ns1.mynameserver.net"; # Time to live (TTL) is a maximum number of seconds your host entry will exist before being refreshed. You want to keep your timeout low so that changes will propagate rapidly in the event of an IP change. $TTL = 60; # Full path to the "nsupdate" command on your system. $nsupdate_cmd = "/usr/bin/nsupdate"; # Full path to a writeable textfile where data can be stored. $nsupdate_command_file = "/var/www/example_nsupdate.dat"; ### THERE SHOULD BE NO NEED TO EDIT BELOW THIS LINE! ### $hostname = $host.'.'.$domain; my $currentDNS = nslookup(host => "$hostname", type => "A", server => "$master_nsserver"); if ($test == 0){ $dyn_new_ip = $ENV{'REMOTE_ADDR'}; } else{ $dyn_new_ip = "111.111.111.111"; } print "Content-type: text/html\n\n"; print "\n"; print "$hostname IP Updater\n"; print "\n"; print "\n"; print "

Current record for $hostname as indicated by $master_nsserver shows your registered IP as $currentDNS.

\n"; print "

Your current IP has been detected as: $dyn_new_ip.

\n"; if ($currentDNS eq $dyn_new_ip){ print "

Record matches. No update required.

\n"; } else { print "

Requesting update from $master_nsserver of $hostname.

\n"; open DYN_NSUPDATE_FILE, ">$nsupdate_command_file" or die $!; print DYN_NSUPDATE_FILE "update delete $hostname a\n"; print DYN_NSUPDATE_FILE "update add $hostname $TTL IN A $dyn_new_ip\n"; print DYN_NSUPDATE_FILE "send\n"; print DYN_NSUPDATE_FILE "\n"; close(DYN_NSUPDATE_FILE); $nsupdate_result = `$nsupdate_cmd -d $nsupdate_command_file 2>&1`; unlink(DYN_NSUPDATE_FILE); print "Output of update request:

$nsupdate_result

\n"; sleep $TTL+1; my $newDNS = nslookup(host => "$hostname", type => "A", server => "$master_nsserver"); if ($newDNS == $dyn_new_ip){ print "

New record registered for $hostname with $master_nsserver now matches $dyn_new_ip. Update was completed sucessfully.

\n"; } else{ print "

Update of $master_nsserver for $hostname failed. Please contact technical support.

\n"; } } print "\n"; print "\n";