Sipdroid's Blog

dyndns python script auto update

Posted in python by sipdroid on February 5, 2010


import sys,re,base64,string,cookielib, urllib, urllib2,httplib

login = 'xxx'
password = 'xxx'

hostlist=''  <--- your host name

m=urllib.urlopen('<a href="')">')</a>
if m :
content =
else :
print ' could not connect to external network '

match ='<body>Current IP Address: (\S)+</body>',content)
if not match :
print ' could not get my external ip address'

ipaddress =
print 'our external IP address is :'+ ipaddress

updatehost = ""
fakeagent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"
updatepage = "/nic/update"
updateprefix = updatepage + "?system=custom&hostname="
updatesuffix = '&myip='+ipaddress

h2 = httplib.HTTPS(updatehost)
h2.putrequest("GET", updateprefix + hostlist + updatesuffix)
h2.putheader("HOST", updatehost)
h2.putheader("USER-AGENT", fakeagent)
authstring = base64.encodestring(login + ":" + password)
authstring = string.replace(authstring, "12", "")
h2.putheader("AUTHORIZATION", "Basic " + authstring)

errcode, errmsg, headers = h2.getreply()

# try to get the html text
fp = h2.getfile()
httpdata =
httpdata = "No output from http request."

print httpdata


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: