How to list all connected nodes in android application (using WIFI)?

493 views Asked by At

It is possible to list all connected nodes in my android application(machines connected to a LAN using wifi)?.

2

There are 2 answers

0
Vickyexpert On BEST ANSWER

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");

2
Vickyexpert 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;
  }