发布时间:2019-09-15 09:57:05编辑:auto阅读(2288)
#!/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()
上一篇: python小整数对象池
下一篇: Python 常见异常列表
52033
51891
42126
38975
33471
30424
29057
24084
23999
22347
73°
112°
128°
117°
137°
133°
154°
171°
172°
176°