我正在尝试访问主机并拥有以下代码
if(!InetAddress.getByName(host).isReachable(TIMEOUT)){
throw new Exception("Host does not exist::"+ hostname);
}
Run Code Online (Sandbox Code Playgroud)
我可以从Windows ping主机名,并在其上执行tracert并返回所有数据包.但java抛出异常"Host is not exists ::";
从实现2000ms到5000ms的超时值.我也试过3000.我无法理解这个问题的原因是什么.我在网上研究过,有人说InetAddress.getByName(host).isReachable(time)不可靠,并且根据内部系统行事.
如果这是真的,最好的选择是什么.请建议.