Detecting android devices connected to Wifi

2020-07-18 05:11发布

I want to make an android application that connects to a Wifi network, say network SSID = "ABC".Assume that it is connected to the Wifi ABC. After connecting to ABC, i would want my application to display the ips of all the android devices that are connected to the same wifi ABC network. How can i achieve that? Thanks

2条回答
Melony?
2楼-- · 2020-07-18 05:28

You will want to use tcpdump to put the network card into promiscous mode and then capture packets to identify what other clients are on your network.

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

You can run commands in your code like so:

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);
}
查看更多
再贱就再见
3楼-- · 2020-07-18 05:36

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

It has the ip and MAC addreses of all the other devices connected to the same network. However I am affraid you wont be able to differentiate if they are android phones or not.

查看更多
登录 后发表回答