Skip to content

Instantly share code, notes, and snippets.

@jfinstrom
Last active January 24, 2018 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jfinstrom/fe3992ef56a7ace48d80 to your computer and use it in GitHub Desktop.
Save jfinstrom/fe3992ef56a7ace48d80 to your computer and use it in GitHub Desktop.
DuckDNS Updater.....
#!/usr/bin/env python
import requests
import sys
#************************************#
# User Serviceable Stuff #
#************************************#
TOKEN = 'YOUR TOKEN'
DOMAIN = 'YOURSUBDOMAIN'
DEBUG = False
## End of user serviceable stuff...
def get_extip():
try:
ip = requests.get('http://ipv4.icanhazip.com').text.rstrip()
if DEBUG:
print "Your External ip is %s" % (ip)
return ip
except requests.exceptions.RequestException as e:
if DEBUG:
print e
return "Failed %s" % (e)
def duck_update(ip):
url = 'https://www.duckdns.org/update'
payload = {'domains':DOMAIN,'token':TOKEN,'ip': ip }
if DEBUG:
print "Sending Update to %s" % (url)
try:
r = requests.get(url, params=payload)
if r.text == 'OK':
if DEBUG:
print "UPDATED"
return True
else:
if DEBUG:
print "Something didn't work\r\n"
print r.url
#this will probably be KO which isn't super helpful....
print r.text
return False
except requests.exceptions.RequestException as e:
if DEBUG:
print e
return "Failed %s" % (e)
def main():
ip = get_extip()
if ip:
duck_update(ip)
else:
sys.exit(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment