Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1730933
  • 博文数量: 234
  • 博客积分: 4966
  • 博客等级: 上校
  • 技术积分: 3322
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-13 01:03
文章分类

全部博文(234)

文章存档

2017年(2)

2016年(1)

2015年(8)

2014年(11)

2013年(44)

2012年(27)

2011年(22)

2010年(30)

2009年(37)

2008年(6)

2007年(45)

2006年(1)

分类: 系统运维

2013-08-25 22:25:23

前一篇已经有一篇这样的文章了,不过脚本是bash脚本,现在又用python重写了一下,主要功能还是在linux下自动更新花生壳的IP,python模块主要是用了httplib2
http://blog.chinaunix.net/uid-8874157-id-3842303.html

花生壳:http协议说明


新python脚本代码如下:

点击(此处)折叠或打开

  1. #!/usr/bin/env python
  2. #coding:utf-8

  3. import httplib2
  4. import sys
  5. import time

  6. def upddns():
  7.     h = httplib2.Http(".cache")
  8.     h.add_credentials(username, password)
  9.     try:
  10.         resp, content = h.request(url+hostname,"GET")
  11.     except httplib2.HttpLib2Error,e:
  12.         print "Error retrieving data:",e
  13.         sys.exit(1)
  14.     return (resp,content)
  15.     
  16. if __name__=="__main__":
  17.     username="******"
  18.     password="******"
  19.     hostname="edgeman03.eicp.net"
  20.     url=""
  21.     
  22.     if "good" or "nochg" in upddns()[1]:
  23.         print "update oray ddns ok!"
  24.         sys.exit(0)
  25.     else:
  26.         print "update oray ddns faild,retry..."
  27.         time.sleep(1)
  28.         upddns()


阅读(4344) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~