Detect Android devices connected to Wi-Fi

I want to make an Android application that connects to a Wi-Fi network, say, SSID = "ABC" network. Suppose it is connected to Wi-Fi ABC. After connecting to ABC, I want my application to display the ips of all Android devices connected to the same ABC network with Wi-Fi. How can i achieve this? Thanks

+4
source share
2 answers

Check the file: / proc / net / arp on your phone.

It has the IP and MAC addresses of all other devices connected to the same network. However, I am afraid that you will not be able to tell if they are Android phones or not.

+4
source

You want to use tcpdump to transfer the network card into promiscous mode, and then capture the packets to determine which other clients are on your network.

How to use tcpdump for android: http://source.android.com/porting/tcpdump.html

You can run commands in your code like this:

try { // Executes the command. Process process = Runtime.getRuntime().exec("/system/bin/ls /sdcard"); // Reads stdout. // NOTE: You can write to stdin of the command using // process.getOutputStream(). BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream())); int read; char[] buffer = new char[4096]; StringBuffer output = new StringBuffer(); while ((read = reader.read(buffer)) > 0) { output.append(buffer, 0, read); } reader.close(); // Waits for the command to finish. process.waitFor(); return output.toString(); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } 
+1
source

Source: https://habr.com/ru/post/1342929/


All Articles