Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # python script to check for IP changes
- # and update a Free DNS account via the Direct URL method
- import syslog
- from urllib import urlopen
- from socket import getaddrinfo
- # insert your Direct URL and DDNS host below
- checkurl = 'http://freedns.afraid.org/dynamic/check.php'
- directurl = 'https://thedirectupdateURLinyourFreeDNSaccount.com'
- ddnshost = 'hostname.you.selected.com'
- def ddns_ip():
- # effectively perform a dns lookup
- try:
- ddnsip = getaddrinfo(ddnshost,'80')[0][4][0]
- syslogwrite('Host ' + ddnshost + ' resolves to: ' + ddnsip)
- except:
- ddnsip = '0.0.0.0'
- syslogwrite('DNS lookup failure')
- return(ddnsip)
- # end ddns_ip
- def actual_ip():
- # get ip detected by freedns website
- try:
- actualip = urlopen(checkurl).read().split()[3]
- syslogwrite('External IP detected as: ' + actualip)
- except:
- actualip = '0.0.0.0'
- syslogwrite('External IP detection failure')
- return(actualip)
- # end actual_ip
- def update_ip():
- # perform Direct URL update
- try:
- # we're not interested in the server's response
- dummy = urlopen(directurl).read()
- syslogwrite('Updating Free DNS IP via Direct URL.')
- except:
- syslogwrite('Direct URL update failed.')
- return 0
- # end update_ip
- def syslogwrite(message):
- syslog.syslog(syslog.LOG_INFO,message)
- return 0
- # end syslogwrite
- # main
- syslogwrite('Automatic update process started.')
- ddnsip = ddns_ip()
- actualip = actual_ip()
- # if lookup was successful
- if not ((ddnsip == '0.0.0.0') or (actualip == '0.0.0.0')):
- # if IPs don't match, carry out update
- if not ddnsip == actualip:
- update_ip()
- # else if lookup was not successful
- else:
- syslogwrite('An error occured.')
- syslogwrite('Automatic update process completed.')
- # end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement