实现:Java代码如下:
String cmd="cmd.exe ping ";
String ipprefix="192.168.10.";
int begin=101;
int end=200;
Process p=null;
for(int i=begin;i<end;i++){
p= Runtime.getRuntime().exec(cmd+ipprefix+i);
String line = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((line = reader.readLine()) != null)
{
//Handling line , may logs it.
}
reader.close();
p.destroy();
}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()
begin += 1;
print "execution result: %s"%p.stdout.read()
Python入门教程--测试局域网中的电脑是否连通,布布扣,bubuko.com
原文:http://blog.csdn.net/cruise_h/article/details/25366589