0

In Android,

  1. How to get the list of devices connected in same WiFi Network?

  2. How to get the nearest devices from your smartphone connected with same WiFi network?

  3. Did frequency check is able to find the nearest device?

Keshava GN
  • 4,195
  • 2
  • 36
  • 47
Narendran
  • 27
  • 1
  • 6

1 Answers1

0

I find the solution for list of devices connected in same network,and i placed the code below

Call this method in onCreate -> getClientList(true, 200);

write this method in our class

  public ArrayList<ClientScanResult> getClientList(boolean onlyReachables, int reachableTimeout) {
    BufferedReader br = null;
    ArrayList<ClientScanResult> result = null;
    try {
        result = new ArrayList<ClientScanResult>();
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        int i = 0;
        while ((line = br.readLine()) != null) {
            String[] splitted = line.split(" +");
            if ((splitted != null) && (splitted.length >= 4)) {
                String mac = splitted[3];
                if (mac.matches("..:..:..:..:..:..")) {
                    boolean isReachable = InetAddress.getByName(splitted[0]).isReachable(reachableTimeout);

                    if (!onlyReachables || isReachable) {
                        result.add(new ClientScanResult(splitted[0], splitted[3], splitted[5], isReachable));
                        i++;
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.e(this.getClass().toString(), e.getMessage());
    } finally {
        try {
            br.close();
        } catch (IOException e) {
            Log.e(this.getClass().toString(), e.getMessage());
        }
    }
    return result;
}

if any clarifications, please reply a message for this post, THANKS

Narendran
  • 27
  • 1
  • 6
  • The file /proc/net/arp does not contain all devices connected to the same network. It is only a cache of recently connected devices. See http://stackoverflow.com/questions/16035636/how-to-get-all-ip-address-of-systems-connected-to-same-wi-fi-network-in-android – Clerenz Jun 09 '16 at 21:16
  • @Narendran after getting the list of connections how to get connect ? – RAJAN Sep 30 '16 at 06:29
  • is it possible to get All Connected Device mac ID and LocalIP ? – Dhiru Jun 27 '18 at 07:42