It is possible to list all connected nodes in my android application(machines connected to a LAN using wifi)?.
How to list all connected nodes in android application (using WIFI)?
493 views Asked by Ram At
2
There are 2 answers
2
On
Try This One...
This will help you
to get all kind of net connections...
public boolean checkNet()
{
ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (netWifi != null && netWifi.isConnected()) {
return true;
}
NetworkInfo netMob = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (netMob != null && netMob.isConnected()) {
return true;
}
NetworkInfo netActive = cm.getActiveNetworkInfo();
if (netActive != null && netActive.isConnected()) {
return true;
}
return false;
}
You can achieve it by following code,
this code is useful in java so not sure but it will work for android also.
public void getAllNodes(String subnet)
{
int pingTime=1000;
String nodeName = "";
for (int i=1;i<254;i++)
{
String host=subnet + "." + i;
if (InetAddress.getByName(host).isReachable(pingTime))
{
nodeName += host;
}
}
}
Just call this method like getAllNodes("192.168.0");