Python 官方文档:入门教程 => 点击学习
#!/usr/bin/env python #_*_coding:u
#!/usr/bin/env python
#_*_coding:utf-8_*_
import pexpect
import datetime
import threading
import os
def Log(log):
f = open('log.txt', 'a+')
f.writelines('%s\n' % log)
f.close()
class PING(threading.Thread):
def __init__(self,ip):
threading.Thread.__init__(self)
self.ip = ip
def run(self):
starttime = datetime.datetime.now()
ping=pexpect.spawn("ping -c1 %s" % (self.ip))
try:
check = ping.expect([pexpect.TIMEOUT,"1 packets transmitted, 1 received, 0% packet loss"],10)
if check == 1:
Log('%s nORMal %s' % (starttime,self.ip))
elif check == 0:
Log('%s timeout %s' % (starttime,self.ip))
except Exception,e:
Log('%s Error %s' % (starttime,self.ip))
os.remove('log.txt')
Thread_list=[]
f = open('iplist','r')
for line in f:
line=line.strip('\n')
ip=line.split()[0]
t = PING(ip)
Thread_list.append(t)
for i in range(len(Thread_list)):
Thread_list[i].start()
--结束END--
本文标题: python threading多线程p
本文链接: https://www.lsjlt.com/news/190015.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0