前一篇已经有一篇这样的文章了,不过脚本是bash脚本,现在又用python重写了一下,主要功能还是在linux下自动更新花生壳的IP,python模块主要是用了httplib2
http://blog.chinaunix.net/uid-8874157-id-3842303.html
花生壳:http协议说明
新python脚本代码如下:
-
#!/usr/bin/env python
-
#coding:utf-8
-
-
import httplib2
-
import sys
-
import time
-
-
def upddns():
-
h = httplib2.Http(".cache")
-
h.add_credentials(username, password)
-
try:
-
resp, content = h.request(url+hostname,"GET")
-
except httplib2.HttpLib2Error,e:
-
print "Error retrieving data:",e
-
sys.exit(1)
-
return (resp,content)
-
-
if __name__=="__main__":
-
username="******"
-
password="******"
-
hostname="edgeman03.eicp.net"
-
url=""
-
-
if "good" or "nochg" in upddns()[1]:
-
print "update oray ddns ok!"
-
sys.exit(0)
-
else:
-
print "update oray ddns faild,retry..."
-
time.sleep(1)
-
upddns()
阅读(4409) | 评论(0) | 转发(0) |