任务:简单测试局域网中的电脑是否连通.这些电脑的ip范围从192.168.0.101到192.168.0.200.  

代码如下:

import subprocess

cmd="cmd.exe"

begin=101

end=200

while begin<end:

   p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,

                  stdin=subprocess.PIPE,

  stderr=subprocess.PIPE)

   p.stdin.write("ping 192.168.1."+str(begin)+"\n")

   p.stdin.close()

   p.wait()

   print "execution result: %s"%p.stdout.read()

   begin=begin+1