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 +" 连接畅通."); } }
时间: 2024-10-05 12:22:41