1

我在同一网络 (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");
  }
}

总是not pingable。有localhost代码就好了。但是Computer2我无法 ping - 但通过 cmd 它正在工作。有任何想法吗?

4

1 回答 1

0

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

于 2013-02-22T14:02:30.777 回答