我正在使用这部分代码来ping通Java中的ip地址,但只有ping通本地主机才能成功,而对于其他主机,该程序表示主机无法访问。我禁用了防火墙,但仍然有此问题
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");
}
输出为:
无法将Ping请求发送到127.0.0.1
主机无法将Ping请求
发送到173.194.32.38
主机