java执行ping命令
public static void get() throws IOException{ String address="10.132.118.110"; 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 +" 连接畅通."); } }