PDA

View Full Version : [Java] Effettuare un ping verso un dato indirizzo IP


di@!
03-07-2012, 23:12
Ciao, conoscete un modo in Java per pingare un dato indirizzo ip con una data porta? Mi spiego meglio...in sostanza devo effettuare un semplice ping verso IP:PORT, in caso positivo effettuare una certa azione, in caso negativo un'altra. Ho trovato questi esempi che perņ non mi aiutano visto che non c'č la porta

try
{
InetAddress inet = InetAddress.getByName("172.16.2.0");
boolean status = inet.isReachable(5000); //Timeout = 5000 milli seconds
}

oppure

if(InetAddress.getByAddress("173.194.35.133".getBytes()).isReachable(1000)==true)
{
//Boolean variable named network
network=true; //Ping works
}
else
{
network=false; //Ping doesnt work
}


qualche idea? Grazie :)

GByTe87
04-07-2012, 11:16
"You can't ping ports, as Ping is using ICMP which doesn't have the concept of ports." :D

http://serverfault.com/questions/309357/ping-a-specific-port

usa nmap o telnet.