//java1.5(有时候机器可以ping通,代码显示false)
public static boolean ping(String ipAddress) throws Exception {
int timeOut = 10000 ; //超时应该在3钞以上
return InetAddress.getByName(ipAddress).isReachable(timeOut);
}//推荐使用
public static boolean ping(String ipAddress) throws Exception {
return 0==Runtime.getRuntime().exec("ping -c 1 "+ipAddress).waitFor();
}
java通过ping测试网络
最新推荐文章于 2025-07-22 12:36:13 发布
本文探讨了两种在Java中实现Ping功能的方法。一种是通过InetAddress的isReachable方法,另一种则是利用Runtime.exec执行系统ping命令。后者更为推荐,因为它能更准确地反映网络状态。
1007

被折叠的 条评论
为什么被折叠?



