简体   繁体   English

检测连接到Wifi的Android设备

[英]Detecting android devices connected to Wifi

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. 我想创建一个连接到Wifi网络的android应用程序,比如网络SSID =“ABC”。假设它连接到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. 连接到ABC后,我希望我的应用程序显示连接到同一wifi ABC网络的所有Android设备的ips。 How can i achieve that? 我怎样才能实现这一目标? Thanks 谢谢

Check out the file: /proc/net/arp on your phone. 在手机上查看文件:/ proc / net / arp。

It has the ip and MAC addreses of all the other devices connected to the same network. 它具有连接到同一网络的所有其他设备的IP和MAC地址。 However I am affraid you wont be able to differentiate if they are android phones or not. 但是,我担心如果他们是Android手机,你将无法区分。

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. 您将需要使用tcpdump将网卡置于promiscous模式,然后捕获数据包以识别网络中的其他客户端。

How to use tcpdump on android: http://source.android.com/porting/tcpdump.html 如何在android上使用tcpdump: 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM