赞
踩
- Process p = Runtime.getRuntime().exec("ping -c 1 -w 1 " + ipString);
- // 读取ping的内容,可不加
- InputStream input = p.getInputStream();
- BufferedReader in = new BufferedReader(new InputStreamReader(input));
- StringBuffer stringBuffer = new StringBuffer();
- String content = "";
- while ((content = in.readLine()) != null) {
- stringBuffer.append(content);
- }
- // PING的状态
- int status = p.waitFor();
- if (status == 0) {
- sleep(3000);
- } else {
- isEnable = false;
- ExDispatcher.dispatchMessage(ExMessage.PING_CONNECT_BREAK);
- interrupt();
- }
- Process process = Runtime.getRuntime().exec("ping "+address);
- InputStreamReader r = new InputStreamReader(process.getInputStream());
- LineNumberReader returnData = new LineNumberReader(r);
- String returnMsg="";
- String line = "";
- while ((line = returnData.readLine()) != null) {
- System.out.println(line);
- returnMsg += line;
- }
-
- if(returnMsg.indexOf("100% loss")!=-1){
- System.out.println("与 " +address +" 连接不畅通.");
- } else{
- System.out.println("与 " +address +" 连接畅通.");
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。