Ping with java to multiplatform?

Since java is not platform independent you can ask which OS you have using the System. GetProperty("os. Name") and parse the response or define the command according to it Alternatively you can use isReachable(int timeout) in InetAddress which seems to be the closest implementation to the ICMP ECHO REQUEST, but it will not provide you the information about loss and round trip time Another Idea would be to use tracert/tracepath instead of ping to get the round trip?

Check this thread for some more information.

Since java is not platform independent you can ask which OS you have using the System. GetProperty("os. Name") and parse the response or define the command according to it.

Alternatively you can use isReachable(int timeout) in InetAddress which seems to be the closest implementation to the ICMP ECHO REQUEST, but it will not provide you the information about loss and round trip time. Another Idea would be to use tracert/tracepath instead of ping to get the round trip? Check this thread for some more information.

1 isReachable - is best effort, if icmp doesn't work it switches to TCP. – Sophie May 31 at 5:49.

You can't do real ICMP with pure Java. The reasonably portable jpcap library provides a nice Java interface to native libraries, though, including ICMP (ping).

I guess parsing is still your easiest option. I would be suprised if you needed more than this regex: timeMs Enclosed in parentheses you will get the time like 1 or 14 or 1.239 which can be fed to Float.parseFloat().

Then "time" will not work. – Sophie May 30 at 14:15 Now that is a problem, still the order of parameters does not change. You have the Windows way and the UNIX way.

– vbence May 30 at 14:26 Also: do you have to literally PING the server? May be a special UDP echo server is enough. (If you have control over the server).

– vbence May 30 at 14:42 yeah it must be ping. Because the purpose is to messure loss and round trip rather then testing if the server alive. – Sophie May 31 at 5:48 @Sophie The same is true for UDP.

Packet loss is also present there (hence the Unreliable). Plus you can send UDP packets even on full throttle which would be the equivalent of flood ping (which can only done by the root user). The things you can't do with UDP: set TTL, set Don't Fragment, set source route.

(The last 2 are ipv4-only). – vbence May 31 at 7:18.

I have used JNI to get the ping command. I have implemented the ping using native (C) and then wrapped it with JNI. The downgrade is that need to compile the C dll per platform.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions