How to do a true Java ping?

Posted by stjowa on Stack Overflow See other posts from Stack Overflow or by stjowa
Published on 2010-03-15T16:20:41Z Indexed on 2010/03/15 16:29 UTC
Read the original article Hit count: 257

Filed under:
|
|

I have a device on a network that I am attempting to ping through my Java program. Through my windows command prompt, I can ping the device address fine and do a tracert on the address fine.

Online, I have seen that in order to do a ping through Java you have to do the following:

InetAddress.getByName(address).isReachable(timeout);

But, when I use this code on my device address, it always returns false in my program. I am using the correct IPv4 address with a good timeout value. Also, if I use a localhost address, it works fine.

Why can I ping the device through cmd, but not through my program? I have heard in various places that this is not a true ping.

Is there a better way to emulate a ping in Java?

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about networking