#!/usr/bin/perl use LWP::Simple; use Net::hostent; use Socket; ############################################# # UpdateIP.pl - dyndns client # # Jeff Israel # # Licences under GPL # ############# # Config $modem = 0; # modem = 1 iff you are my modem $host = "domain.dyndns.org"; $log = "/home/scripts/log"; $username = "USER"; $password = "PASS"; $sleeptime = "1h"; # example 3h 4m $system = "dyndns"; #system=dyndns|statdns|custom $wildcard = "OFF"; #wildcard=ON|OFF|NOCHG #http://username:password@members.dyndns.org/nic/update?system=dyndns&hostname=yourhost.ourdomain.ext,yourhost2.dyndns.org&myip=ipaddress&wildcard=OFF&mx=mail.exchanger.ext&backmx=NO&offline=NO #$crack = get("http://$username:$password\@members.dyndns.org/nic/update?system=$system&hostname=$host&myip=202.202.202.202&wildcard=$wildcard"); #print $crack; print "\nThe Wonderful Dynamic IP Updater\n\n"; while(1){ ########################### # Specific to my modem # $modem = 1 # otherwise set $modem = 0 if ($modem == 1){ $content = get("http://10.0.0.1/vc_56xx.html"); #print "$content"; @scraps = split(//,$ip) ; #print $scraps[1]; $ip = $scraps[1]; } else{ $content = get("http://checkip.dyndns.org/"); @scraps = split(/ /,$content); @scraps = split(/; close(INFO); chop($lines[0]) if $lines[0] =~ /\n$/; $fileip = $lines[0]; #print "eep"; ################# # gets ip currently registered to domain unless ($h = gethost($host)) { warn "$0: no such host: $host\nMaybe you are not online"; system "sleep $sleeptime"; next; } $regip = inet_ntoa($h->addr); ######################### # checks to see if they match, if not corrects print "IP Addesses: file = $fileip domain = $regip current = $ip\n"; if(($fileip eq $ip) && ($regip eq $ip)){ print "Everything Up to Date\nSleeping...\n "; system "sleep $sleeptime"; } elsif ($regip ne "" && $ip ne ""){ if($fileip ne $ip){ open(OUTF,">$log"); print OUTF "$ip\n"; close(OUTF); } if($regip ne $ip){ print "\n\nIP = $ip \n\n Domain = $host \n\n"; # system "updatedd --wildcard off --ip $ip --hostnames $host --user $username:$password --system dyndns"; $return = get("http://$username:$password\@members.dyndns.org/nic/update?system=$system&hostname=$host&myip=$ip&wildcard=$wildcard"); @returns = split(/ /,$return); if ($returns[0] eq "good"){ print "Updated Sucsesfully\nSleeping...\n "; }else{ print "Error Sending Update, check configuration: error code returned: $return\n\nbadsys - The system parameter given is not valid. Valid system parameters are dyndns, statdns and custom.\nbadagent - The user agent that was sent has been blocked for not following these specifications or no user agent was specified.\nbadauth - The username or password specified are incorrect.\n!donator - An option available only to credited users (such as offline URL) was specified, but the user is not a credited user.\nnochg - The update changed no settings, and is considered abusive. Additional nochg updates will cause the hostname to become blocked.\n"; print "notfqdn - The hostname specified is not a fully-qualified domain name (not in the form hostname.dyndns.org or domain.com).\nnohost - The hostname specified does not exist (or is not in the service specified in the system parameter) \n!yours - The hostname specified exists, but not under the username specified. \nabuse - The hostname specified is blocked for update abuse. \nnumhost - Too many or too few hosts found.\n dnserr - DNS error encountered.\n\n"; } system "sleep $sleeptime"; } }else{ print "IP Addesses: file = $fileip domain = $regip current = $ip\n"; print "ERROR: Posibly not online\nSleeping... \n"; system "sleep $sleeptime"; } }