Detecting android devices connected to Wifi

谁说胖子不能爱 提交于 2019-12-04 10:32:45

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.

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);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!