kiran kiran - 10 days ago 5
Android Question

How to display IP address of devices which are connected to android hotspot programmatically?

I need to display ip address of devices which are connected to android hotspot in a app.

Please help me

Answer

You have the client info in the system file: /proc/net/arp You will need External Storage permission.

File content example:

IP address       HW type     Flags       HW address            Mask     Device 
192.168.43.40    0x1         0x2         c0:ee:fb:43:e9:f8     *        wlan0

You should parse the file and get the data.

For example, you can try something like that:

public ArrayList<String> getClientList() {
    ArrayList<String> clientList = new ArrayList<>();
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader("/proc/net/arp"));
        String line;
        while ((line = br.readLine()) != null) {
            String[] clientInfo = line.split(" +");
            String mac = clientInfo[3];
            if (mac.matches("..:..:..:..:..:..")) { // To make sure its not the title
                clientList.add(clientInfo[0]);
            }
        }
    } catch (java.io.IOException aE) {
        aE.printStackTrace();
        return null;
    }
    return clientList;
}

***Tested on rooted device.