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

有帮助吗?

解决方案

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

其他提示

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;
  }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top