List of connected hotspot devices

1.1k Views Asked by At

I would like to retrieve the IP addresses of all devices connected to the WiFi hotspot of my smartphone. In Android 10 and below, I was able to get this list by executing the following piece of code:

Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("ip neigh show");
proc.waitFor();
int exit = proc.exitValue();
InputStreamReader reader = new InputStreamReader(proc.getInputStream());
BufferedReader buffer = new BufferedReader(reader);
String line;
while ((line = buffer.readLine()) != null) {
     String[] splits = line.split(" ");
     if (splits.length < 4) {
         continue;
     }
     if(!splits[0].contains("192.168.43.")) {
         Log.d("IP", splits[0]);
         continue;
     }
}

However, it seems the IP command is no longer working in Android 11 (https://developer.android.com/training/articles/user-data-ids#mac-11-plus)

The ip command does not return information about interfaces.

Is there any other way to obtain the IP address of a connected client in Android 11?

2

There are 2 best solutions below

0
Luigino On

just this morning I tried that command "ip neigh show" using Termux app on an Android 11 phone and it worked and gave me results of neighbours....

1
mihai71 On

Life-saving solution, considering that Android 10 + won't give you access to "/proc/net/arp" file anymore. Working on Android11, Samsung S10 and Samsung M12.