I have here 2 Windows systems in the same network (XP). If I open cmd and I type
ping Computer2
I get an answer (so ping is working). I thought I could do this with Java also, but somehow it's not working:
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");
}
}
Always not pingable
. With localhost
the code is fine. But with Computer2
I'm not able to ping - but via cmd it's working. Any ideas?