Skip to content

Instantly share code, notes, and snippets.

@demophoon
Created January 11, 2015 05:22
Show Gist options
  • Save demophoon/bc6b5bea6f39de724934 to your computer and use it in GitHub Desktop.
Save demophoon/bc6b5bea6f39de724934 to your computer and use it in GitHub Desktop.
Namecheap DDNS Script
#!/usr/bin/env python
# encoding: utf-8
import urllib
NAMECHEAP_BASE_URL = "https://dynamicdns.park-your-domain.com/update?"
def get_public_ip():
"""
Gets the public ip address of the system
"""
get_ip_url = "http://api.ipify.org"
return urllib.urlopen(get_ip_url).read()
def main():
"""
Update Namecheap's Dynamic DNS with the public ip address of the computer
that this script is currently running.
"""
request_params = {
'host': 'subdomain',
'domain': 'example.com',
'password': 'password',
'ip': get_public_ip(),
}
params = urllib.urlencode(request_params)
response = urllib.urlopen(NAMECHEAP_BASE_URL + params).read()
if "<ErrCount>0</ErrCount>" not in response:
print response
raise Exception("There was an error updating the entry")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment