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