Programatically using ICMP Ping is a great way to establish that a server is up and running. Programatically utilizando ICMP Ping es una buena manera de establecer que un servidor está en marcha y funcionando. Previously you couldn’t do ICMP ping (what ping command does in Linux/Unix & Windows) in java without using JNI or exec calls. Anteriormente usted no puede hacer ping ICMP (comando ping lo hace en Linux / Unix y Windows) en Java sin utilizar JNI o exec llamadas. Here is a simple and reliable method to do ICMP pings in Java without using JNI or NIO. He aquí una sencilla y fiable método para hacer pings ICMP en Java sin utilizar JNI o NIO.


String host = “172.16.0.2″ String host = "172.16.0.2"
int timeOut = 3000; // I recommend 3 seconds at least int timeout = 3000; / / recomiendo 3 segundos a menos
boolean status = InetAddress.getByName(host).isReachable(timeOut) boolean status = InetAddress.getByName (host). isReachable (timeout)

status is true if the machine is reachable by ping; false otherwise. condición es verdadera si la máquina se llega por ping; false en caso contrario. Best effort is made to try to reach the host, but firewalls and server configuration may block requests resulting in a unreachable status while some specific ports may be accessible. Mejor esfuerzo se haga para tratar de llegar a la acogida, pero los cortafuegos y la configuración del servidor puede bloquear las solicitudes resultantes en un estado inalcanzable mientras que algunos puertos específicos pueden ser accesibles. A typical implementation will use ICMP ECHO REQUESTs if the privilege can be obtained, otherwise it will try to establish a TCP connection on port 7 (Echo) of the destination host. Una típica aplicación utilizará las peticiones ICMP ECHO si el privilegio se puede obtener, de lo contrario, tratar de establecer una conexión TCP en el puerto 7 (Echo), de un destino de acogida.

In Linux/Unix you may have to suid the java executable to get ICMP Ping working, ECHO REQUESTs will be fine even without suid. En Linux / Unix puede ser que haya suid el ejecutable de Java para obtener ICMP Ping de trabajo, ECHO solicitudes se multa, incluso sin suid. However on Windows you can get ICMP Ping without any issues whatsoever. Sin embargo en Windows puede obtener ICMP Ping sin problemas en absoluto.