Reputation: 85
I'm trying to develop a method that checks if an IP direction is reachable and I found a similar question but it doesn't work Android Application Ping IP number
private void existePingServidor(){
InetAddress in;
try{
in = InetAddress.getByName("90.0.0.122");
if (in.isReachable(5000)){
pingServidor = true;
Log.v("true","He pasado por aquí");
}
else
pingServidor = false;
Log.v("false", "No he podido alcanzar la ip");
}
catch(Exception e){
e.printStackTrace();
}
}
The problem seems that InetAddress.getByName("90.0.0.122"); returns null
¿Can you explain me what is the proper way to ping a Ip in android studio please?
Upvotes: 1
Views: 674
Reputation: 104589
Try getByAddress instead:
byte [] ip = {90, 0, 0, 122};
addr = InetAddress.getByAddress(ip);
addr.isReachable(5000);
Upvotes: 1