4
votes

Are there any methods to ping icmp (echo request) instead of using isReachable? isReachable establish a TCP connection on port 7 and when I used wireshark I did not see any ICMP packets on Window and ICMP type 3 on Linux (not type 8 and 0). So if someone have suggestions or solutions could you please tell me. Thanks a lot!

2
TCP/7 is the TCP echo service, FYI. You cannot create raw sockets, at least not with Java 6, and ping requires that.fge

2 Answers

3
votes

ICMP tends to require administrative privileges, so a Java program running as a regular user cannot directly use ICMP.

The only workaround that comes to my mind would be to spawn an external program to run the OS-provided "ping" command and parse its output.

0
votes

We have had good luck using the Parallec library (http://www.parallec.io/).

Before that we ran the ping command line utility provided by Linux using Runtime.exec().

As mentioned above, isReachable will use ICMP if you run as a privileged user, otherwise it uses TCP.