gpt4 book ai didi

java - 为什么我无法 ping 通计算机?

转载 作者:行者123 更新时间:2023-12-01 04:50:40 27 4
gpt4 key购买 nike

我在同一网络 (XP) 中有 2 个 Windows 系统。如果我打开 cmd 并输入

ping Computer2

我得到了答案(所以 ping 正常)。我以为我也可以用 Java 做到这一点,但不知何故它不起作用:

public static void ping() {

System.out.println("Ping Poller Starts...");
final String computer = "Computer2";

InetAddress inet = null;
try {
inet = InetAddress.getByName(computer);
} catch (UnknownHostException e) {
e.printStackTrace();
}
System.out.println("Sending Ping Request to " + computer);

boolean status = false;
try {
status = inet.isReachable(5000);
} catch (IOException e) {
e.printStackTrace();
}

if (status)
{
System.out.println(computer + " ok");
}
else
{
System.out.println(computer + " not pingable");
}
}

始终无法 ping 通。使用 localhost 代码就可以了。但是对于 Computer2 我无法 ping - 但通过 cmd 它可以工作。有什么想法吗?

最佳答案

不清楚您是否要 ping IP 地址或计算机名称,但可能很简单,例如使用“\Computer2”而不是“Computer2”。

关于java - 为什么我无法 ping 通计算机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15025874/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com