我正在使用这部分代码在java中ping一个ip地址,但只有ping localhost是成功的,对于其他主机,程序说主机无法访问。我禁用了我的防火墙,但仍然有这个问题
public static void main(String[] args) throws UnknownHostException, IOException {
String ipAddress = "127.0.0.1";
InetAddress inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");
ipAddress = "173.194.32.38";
inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");
}
输出是:
向 127.0.0.1
主机
发送 Ping 请求可达 向 173.194.32.38
主机发送 Ping 请求不可达