Como fazer ping em um endereço IP
Eu estou usando essa parte do código para pingar um endereço IP em java, mas somente ping localhost é bem-sucedido e para os outros hosts o programa diz que o host está inacessível. Eu desativei meu firewall, mas ainda tenho esse problema
public static void main(String[] args) throws UnknownHostException, IOException {
String ipAddress = "127.0.0.1";
InetAddress inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");
ipAddress = "173.194.32.38";
inet = InetAddress.getByName(ipAddress);
System.out.println("Sending Ping Request to " + ipAddress);
System.out.println(inet.isReachable(5000) ? "Host is reachable" : "Host is NOT reachable");
}
A saída é:
Envio de solicitação de ping para 127.0.0.1
Anfitrião é alcançável
Envio de solicitação de ping para 173.194.32.38
Host não é alcançável