3

I have done a fair amount of research these last few weeks trying to create a connection diagnostic tool, I don't so much want to just check to see if the connection is available but to diagnose if there is jitter, packet loss, etc..

So far it seems that Java doesn't support a true ICMP request and that there are a few workarounds out there but none of which achieve what I'm trying to do.

Does anyone know if this sort of tool can be built or should I start looking into other options?

lael
  • 31
  • 1
  • 3
  • I'm not sure how it's done - so I can't help in that retrospect, however - online speedtests used to offer this functionality (I think pingtest.net) still does, so it's definitely doable - I'm just not sure how, sorry and best of luck! – Jack hardcastle Mar 10 '15 at 16:21
  • Pingtest.net does exactly that but it only runs 4 pings and is not very powerful. My hope was to write a program that would ping multiple addresses hundreds of times and export the data to a text file for analysis. Thanks for the answer tho! (: – lael Mar 10 '15 at 19:54

3 Answers3

3

It seems that InetAdress is using ICMP when its possible:

https://docs.oracle.com/javase/7/docs/api/java/net/InetAddress.html

take a look at public boolean isReachable(int timeout)

Test whether that address is reachable. Best effort is made by the implementation to try to reach the host, but firewalls and server configuration may block requests resulting in a unreachable status while some specific ports may be accessible. A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained, otherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host.

You can find a simple use example here: How to test if a remote system is reachable or here How to ping an IP address

Marcin
  • 195
  • 1
  • 7
1

I believe ICMP4J does exactly what you need: Internet Control Message Protocol for Java

sergpank
  • 988
  • 10
  • 18
  • 1
    ICMP4J uses the os it's running on by starting a ping process call. It doesn't send it from java itself. I'm not sure if OP considers this as 'true ping'. – Martin Dec 23 '20 at 10:19
0

You can use 'Exec' to run ping at the command line (assuming your OS supports this), or JNI to interface to a native application to do the pinging.

Creating your own implementation of the ICMP protocol would not be trivial.

If you do use Exec be aware of it's limitations which are not always obvious in initial testing:

Mick
  • 24,231
  • 1
  • 54
  • 120