I want to test whether a remote system is reachable using Java or in other words "send a ping" using Java. This functionality should be encapsulated in a method with boolean value, for example
public boolean isReachable(String ip) {
// what to do :-)
}
I've tested the Java Process class, but I don't think that it is the best way to do this, because of the complex output handling with OutputBuffers.
Process proc = Runtime.getRuntime().exec("ping " + ip);
Another possibility would be creating a Socket Connection and handle thrown exceptions, but if the remote system is a "naked" unix system, there might be no Socket on the other side :-) Additionally, I'd like to be able to set a timeout, when a remote system is not reachable.
So how could I do this? Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…