I am trying to map the local network to see how many devices (particularly a device I have built) there are on the network and what IP addresses they have. There are a few methods on this that I have found:
List devices on local network with ping
Why does InetAddress.isReachable return false, when I can ping the IP address?
How do I test the availability of the internet in Java?
The last link is the one I have been able to get working, but it is not very reliable (at least not my implementation of it). When I run the code on my phone it will rarely detect my device (only a few out times of dozens of attempts) on the network.
The device is a TI CC3200 that I have setup as a webserver. I am able to reliably ping the CC3200 with my laptop and I can access the webpage on it nearly 100% of the time using my laptop, phone browser, or using WebView in the app.
I have a serial link with the CC3200 and I can see that the app connects to the CC3200 while it is scanning the network.
I am I doing something incorrect? or is there a better method of mapping the local network that I should focus my effort on?
public boolean scan(final String IP) {
Globals success = Globals.getInstance();
success.setDataString(IP);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Globals success = Globals.getInstance();
URL url = new URL("http://" + IP);
URLConnection conn = url.openConnection();
conn.setConnectTimeout(2000);
conn.setReadTimeout(2000);
InputStream in = conn.getInputStream();
success.setDataBool(true);
} catch (SocketTimeoutException e) {
Globals success = Globals.getInstance();
success.setDataBool(false);
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
thread.start();
//boolean temp2 = success.getDataBool();
return success.getDataBool();
}
}