java通过ping测试网络

//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测试网络)