-# we need to update the IP
-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()
-if 'good '+myip == result:
- # nothing to do, all went all right
- sys.exit(0)
+def update_domain(domain):
+ '''Update the given domain, using the global server, user, password. Returns True on success, False on failure.'''
+ # check if the domain is already mapped to our current IP
+ myip = urllib2.urlopen('https://'+server+'/checkip').read().strip()
+ domainip = socket.gethostbyname(domain)
+ if myip == domainip:
+ # nothing to do
+ return True
+
+ # we need to update the IP
+ result = urllib2.urlopen('https://'+server+'/update?password='+urllib.quote(password)+'&domain='+urllib.quote(domain)+'&ip='+urllib.quote(myip)).read().strip()
+ if 'good '+myip == result:
+ # all went all right
+ return True
+ else:
+ # Something went wrong
+ print "Unexpected answer from server",server,"while updating",domain,"to",myip
+ print result
+ return False