0

Working with Android Application, the user enter a network IP number inside a editview Ex: (192.100.10.10). I want to see if that network IP exist before go further on.

user3215134
  • 41
  • 2
  • 5
  • @ChrisStratton yes they have something that half works. But both questions are still essentially "how can I ping in android?". – weston May 27 '14 at 13:05

1 Answers1

0

Your code should look somehow like this:

InetAddress in;
//try to parse address
try {
    in = InetAddress.getByName("192.100.10.10");
} catch (UnknownHostException e) {
    //incorrect IP
}

try {
    //wait for response (500ms)
    if (in.isReachable(5000)) {
        //host reachable
    } else {
        //no host found/timeout
    }
} catch (IOException e) {
    // IOException
}

credit goes to How to Ping External IP from Java Android

Community
  • 1
  • 1
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76