################### ## ## ZoneEdit.Com Dynamic IP script ## v0.9 ## ################### use Sys::Hostname; use LWP::UserAgent; #### README: change these to match the zones you want #### TODO: put these in a configuration file, and prompt the user for them the first time he runs it $zones = 'mydomain.com'; $pass = 'mypass'; $login = 'mylogin'; #### README: (optional) change these to a directory where you want them to be... ie: /var/log or c:/temp $logfile = 'ze-ip.log'; $ipfile = 'ze-ip.txt'; #clear the logfile clear(); mark("START",100,"Starting dynamic IP program"); while (1) { #read the previous ip address open S, "$ipfile"; $prev_ip = ; close S; #get the current ip address ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname(Sys::Hostname::ghname()); ($a,$b,$c,$d) = unpack('C4',$addrs[0]); $ip = "$a.$b.$c.$d"; if (!($ip eq $prev_ip)) { #report the current ip address to zoneedit.com $ua = new LWP::UserAgent; $ua->credentials('dynamic.zoneedit.com:80', 'DNS Access', $login, $pass); $request = new HTTP::Request('GET', "http://dynamic.zoneedit.com/auth/dynamic.html?zones=$zones"); $response = $ua->request($request); if ($response->is_success) { #record successful update of the ip address open S, ">$ipfile"; print S $ip; close S; } else { mark("ERROR", $response->code, $response->message); } } sleep(10); } sub mark { my ($type, $code, $message) = @_; open E, ">>$logfile"; print localtime()."\t$type\t".$code."\t".$message."\n"; print E localtime()."\t$type\t".$code."\t".$message."\n"; close E; } sub clear { open E, ">$logfile"; close E; } # - Erik Aronesty, # ZoneEdit, Inc.