[python]測試局域網中電腦是否連通

生命苦短,我用python

參考http://www.jb51.net/article/926.htmpython2.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"

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章