« | September 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
| 公告 |
戒除浮躁,读好书,交益友 |
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() |
|
|