Вопрос

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