希网3322域名更新脚本(Python)

来源:互联网 发布:10型军用巧克力淘宝 编辑:程序博客网 时间:2024/05/17 22:41
import re,urllib2class DDNS:    def getip(self):        try:            myip = self.visit("http://www.whereismyip.com/")        except:                try:                    myip = self.visit("http://www.ip138.com/")                except:                    myip = None        return myip    def visit(self,url):        opener = urllib2.urlopen(url)        if url == opener.geturl():            str = opener.read()        return re.search('\d+\.\d+\.\d+\.\d+',str).group(0)    def updateIP(self):        ip=self.getip()        if(ip==None):            break        auth= urllib2.HTTPPasswordMgrWithDefaultRealm()        url = "http://members.3322.net/dyndns/update?system=dyndns&myip="+ip+"&hostname=test.3322.org"        auth.add_password(None, url, user='test',passwd='test123')        handler = urllib2.HTTPBasicAuthHandler(auth)        opener = urllib2.build_opener(handler)        urllib2.install_opener(opener)         f=urllib2.urlopen(url)        print f.read()if __name__ == '__main__':     DNS = DDNS()    DNS.updateIP()

0 0
原创粉丝点击