发布时间:2019-09-15 09:57:05编辑:auto阅读(1671)
#!/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 常见异常列表
47846
46395
37285
34736
29316
25974
24917
19952
19547
18031
5793°
6416°
5930°
5963°
7065°
5912°
5946°
6439°
6405°
7781°