本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告

戒除浮躁,读好书,交益友


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:邢红瑞的blog
日志总数:523
评论数量:1142
留言数量:0
访问次数:9708058
建立时间:2004年12月20日




[脚本语言]python线程的使用(网上抄的)
文章收藏,  网上资源,  软件技术,  电脑与网络

邢红瑞 发表于 2007/7/1 18:48:59

 ping 10个主机的Python程序import osimport reimport timeimport sysfrom threading import Thread class testit(Thread):   def __init__ (self,ip):      Thread.__init__(self)      self.ip = ip      self.status = -1   def run(self):      pingaling = os.popen("ping -q -c2 "+self.ip,"r")      while 1:        line = pingaling.readline()        if not line: break        igot = re.findall(testit.lifeline,line)        if igot:           self.status = int(igot[0]) testit.lifeline = re.compile(r"(\d) received")report = ("No response","Partial Response","Alive") print time.ctime() pinglist = [] for host in range(60,70):   ip = "192.168.200."+str(host)   current = testit(ip)   pinglist.append(current)   current.start() for pingle in pinglist:   pingle.join()   print "Status from ",pingle.ip,"is",report[pingle.status] print time.ctime()


阅读全文(3788) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144761674 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号