您的位置:首页 > 编程语言 > Python开发

[python]测试局域网中电脑是否连通

2012-12-17 10:17 239 查看
生命苦短,我用python

参考/article/1281069.html
python2.7.3在线文档

'''
Created on 2012-9-9

@author: jincheng
'''
from ctypes import *
import subprocess
#输入参数
cmd="cmd.exe"
print "ip:"
ip=raw_input()
print "begin:"
begin=raw_input()
print "end:"
end=raw_input()
print "start"

#循环
#python特性1:不符合缩进的不予编译
while int(begin)<int(end):
#新建线程
p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
#ping
p.stdin.write("ping "+ip+str(begin)+"\n")
p.stdin.close()
p.wait()
print "execution result:%s" %p.stdout.read()
begin=int(begin)+1

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