Ping via InetAddress.isReachable().
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.io.IOException;
class Ping {
public static void main(String[] args) {
InetAddress in;
try {
in = InetAddress.getByName(args[0]);
boolean result = in.isReachable(5000);
if (result) {
System.out.println("Response OK");
}
else {
System.out.println("Response fail");
}
} catch (UnknownHostException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}