怎样快速的判断服务器是否开启的

2024-12-16 16:00:06
推荐回答(2个)
回答1:

用过这个方法没?
:调出DOS窗口,ping IP或域名,有返回值就是开启的,这个应该是最快的了。

回答2:

[mw_shl_code=java,true] public static String pingIpAddr() { String pingInfo = "ok"; try { String ipAddress = "123.123.1.13"; Process p = Runtime.getRuntime().exec("ping -c 1 -w 100 " + ipAddress); int status = p.waitFor(); if (status == 0) { return pingInfo; } else { pingInfo = "错误:服务器没开启"; } } catch (IOException e) { pingInfo = "错误:服务器IO错误"; } catch (InterruptedException e) { pingInfo = "错误:网络拥堵"; } return pingInfo; }[/mw_shl_code]