/** * 检测IP是否可以ping通 * @param IP * @return */ private static String pingIP(String IP) { BufferedReader in = null; Runtime rt = Runtime.getRuntime(); boolean FoundMatch = false; String pingCommand = "ping " + IP + " -w " + 3000; try { Process pro = rt.exec(pingCommand); in = new BufferedReader(new InputStreamReader(pro.getInputStream())); String line = in.readLine(); while (line != null) { try { Pattern Regex = Pattern.compile("(T|t){2}(L|l)", Pattern.CANON_EQ); Matcher RegexMatcher = Regex.matcher(line); FoundMatch = RegexMatcher.find(); if (FoundMatch) { pro.destroy(); return IP.trim(); } } catch (PatternSyntaxException ex) { // Syntax error in the regular expression ex.getMessage(); } line = in.readLine(); } } catch (IOException e) { // TODO Auto-generated catch block System.out.println(e.getMessage()); } return null; }
java 判断能否ping通_java检测计算机是否可以ping通
最新推荐文章于 2024-04-22 11:34:31 发布