首页 文章

检测连接到Wifi的Android设备

提问于
浏览
4

我想创建一个连接到Wifi网络的android应用程序,比如网络SSID =“ABC” . 假设它连接到Wifi ABC . 连接到ABC后,我希望我的应用程序显示连接到同一wifi ABC网络的所有Android设备的ips . 我怎样才能实现这一目标?谢谢

2 回答

  • 1

    在手机上查看文件:/ proc / net / arp .

    它具有连接到同一网络的所有其他设备的IP和MAC地址 . 但是,我担心如果他们是Android手机,你将无法区分 .

  • 4

    您将需要使用tcpdump将网卡置于promiscous模式,然后捕获数据包以识别网络中的其他客户端 .

    如何在android上使用tcpdump:http://source.android.com/porting/tcpdump.html

    您可以在代码中运行命令,如下所示:

    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);
    }
    

相关问题