Ping uses ICMP, which is not available in java. This might be the best way to execute a ping server in java:
try{
String s = null;
List<String> commands = new ArrayList<String>();
commands.add("ping");
commands.add("192.168.2.154");
ProcessBuilder processbuilder = new ProcessBuilder(commands);
Process process = processbuilder.start();
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null)
{
System.out.println(s);
}
}catch (Exception e) {
System.out.println("This is sad ");
}
Another way could be working with pure Java sockets.
source
share