|
查看地址:http://www.xheike.com/forum.php?mod=viewthread&tid=1755
publicsynchronizedstaticString getIntelIp(String describe,String ip){
Process p=null;
BufferedReader in=null;
try{
p = Runtime.getRuntime().exec("cmd /c ping -n 1 "+ ip); // 此处1变大可以增加精确度,但影响测试速度
//缓冲读取
in = newBufferedReader(newInputStreamReader(p
.getInputStream(),"gbk"));
String temp = null;
StringBuffer strBuffer = newStringBuffer();
while((temp = (in.readLine())) != null)
strBuffer.append(temp);
// System.out.println(strBuffer.toString().matches(".*\(\d?\d% loss\).*"));
// System.out.println(strBuffer);
in.close();
if(strBuffer.toString().contains("请求超时")) {
returndescribe+"网络连接异常";
} else{
returndescribe+"网络连接正常";
}
} catch(IOException e) {
e.printStackTrace();
returndescribe+"监测网络异常";
}
} |
|
|