receive notifications when users connected an WIFI access point

549 views Asked by At

I want to define a connection to my access point. I want receive notifications when users connected. I know that I can query arp table(/proc/net/arp) , from which I can find connected users. Here is the sample code:

public static ArrayList<ClientScanResult> getClientList() {
    BufferedReader br = null;
    ArrayList<ClientScanResult> result = null;

    try {
        result = new ArrayList<ClientScanResult>();
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] splitted = line.split(" +");
            Log.d("Debug:line=", line);
            if ((splitted != null) && (splitted.length >= 4)) {
                // Basic sanity check
                String mac = splitted[3];

                if (mac.matches("..:..:..:..:..:..")) {
                    result.add(new ClientScanResult(splitted[0], splitted[3], splitted[5]));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return result;
}

Question: is there any better way to do this, except viewing arp-table every n seconds?

UPD: If you connect to an access point, and then disconnect, then the record will still be in the arp-table.That is, until I can not get a list of all connected users

1

There are 1 answers

7
Chen Kinnrot On