Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ping with java to multiplatform

I need to perform ping to some ip/machine. The code may be executed on any kind of platform (windows, linux, mac) and i need to get the information about loss and the round trip time. so java's exec of ping is not good enough because then i need to parse ping response as string, which is different per platform and per OS language. so what do i need to do? I know there is something like JNI, but i'm new to java, so need a little help here. it still means i need to have native implementation per platform? Any examples or suggestions?

like image 987
Sophie Avatar asked May 30 '11 13:05

Sophie


1 Answers

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.

like image 137
CloudyMarble Avatar answered Sep 29 '22 19:09

CloudyMarble