您的位置:首页 > 移动开发 > 微信开发

测试ping小程序

2015-10-08 17:03 561 查看
#!/usr/bin/env python
import os,sys,re
import subprocess
import threading

nameList = eval(sys.argv[1])

def runCheck(file_obj):
for host in file_obj:
host = host.strip('\n')
p = subprocess.Popen(["ping -c 1 "+ host],
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = True)
out = p.stdout.read()
regex = re.compile("time=\d*", re.IGNORECASE | re.MULTILINE)
if len(regex.findall(out)) > 0:
print host+': Host Up!'
else:
print host+': Host Down!'

runCheck(nameList)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python