检测连接到 Wifi 的 Android 设备

发布于 2024-10-20 23:25:36 字数 143 浏览 5 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

前事休说 2024-10-27 23:25:36

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

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

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.

踏雪无痕 2024-10-27 23:25:36

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

如何在 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);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文