add checkip script and a client to update the IP
[dyn-nsupdate.git] / client.py
1 #!/usr/bin/python
2 import urllib2, socket, urllib, sys
3 # configuration variables
4 user = 'yourusername'
5 password = 'yourpassword'
6 domain = 'your.domain.ralfj.de'
7 # END of configuration variables
8 myip = urllib2.urlopen('https://ns.ralfj.de/checkip').read().strip()
9 currip = socket.gethostbyname(domain)
10 if myip == currip:
11         # nothing to do
12         sys.exit(0)
13
14 # we need to update the IP
15 result = urllib2.urlopen('https://ns.ralfj.de/update?user='+urllib.quote(user)+'&password='+urllib.quote(password)+'&domain='+urllib.quote(domain)+'&ip='+urllib.quote(myip)).read().strip()
16 if 'good '+myip == result: 
17         # nothing to do, all went all right
18         sys.exit(0)
19
20 # there was an error :(
21 print result