Last active
January 24, 2018 12:20
-
-
Save jfinstrom/fe3992ef56a7ace48d80 to your computer and use it in GitHub Desktop.
DuckDNS Updater.....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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