【问题标题】:Detecting android devices connected to Wifi检测连接到 Wifi 的安卓设备
【发布时间】:2011-03-09 02:38:06
【问题描述】:

我想制作一个连接到 Wifi 网络的 android 应用程序,比如 network SSID = "ABC"。假设它已连接到 Wifi ABC。连接到 ABC 后,我希望我的应用程序显示连接到同一个 wifi ABC 网络的所有 android 设备的 ip。我怎样才能做到这一点?谢谢

【问题讨论】:

  • 欢迎来到 Stack Overflow!请避免使用答案发布附加信息或跟进对其他答案的回复。只需编辑您的问题以提供说明,或使用每个已发布答案下的 cmets 直接与其作者互动。

标签: android wifi social-networking mobile-devices


【解决方案1】:

在您的手机上查看文件:/proc/net/arp。

它具有连接到同一网络的所有其他设备的 ip 和 MAC 地址。但是我担心你无法区分它们是否是安卓手机。

【讨论】:

    【解决方案2】:

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

    如何在安卓上使用 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);
    }
    

    【讨论】:

    • 假设我正在接收为所有设备指定的数据包,包括连接到 wifi 的任何计算机或移动设备,我如何能够仅通过查看来区分 android 设备和非 android 设备数据包?有没有一种方法可以通过应用程序发送/接收数据包来区分数据包/进程?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-13
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    相关资源
    最近更新 更多