2011-03-09 144 views
4

我想制作连接到Wifi网络的Android应用程序,例如网络SSID =“ABC”。假设它连接到Wifi ABC。连接到ABC后,我希望我的应用程序显示连接到同一个无线网络ABC网络的所有Android设备的ips。我怎么能做到这一点?谢谢检测连接到Wifi的Android设备

+0

欢迎来到Stack Overflow!请避免使用答案发布其他信息或跟进对其他答案的答复。只需编辑您的问题以提供澄清,或者使用每个发布的答案下的评论直接与其作者进行交互。 – 2011-03-12 08:37:07

回答

1

您将要使用tcpdump将网卡置于promiscous模式,然后捕获数据包以确定您的网络上还有其他客户端。

如何使用tcpdump的Android上:您的手机上的/ proc /净/ ARP: 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); 
} 
+1

假设我正在接收为所有设备指定的数据包,其中包括任何连接到无线网络的计算机或移动设备,如何通过查看数据包来区分Android设备和非Android设备?通过发送/接收数据包的应用程序可以区分数据包/进程吗? – Farhan 2011-03-12 06:06:31

4

签出该文件。

它具有连接到同一网络的所有其他设备的ip和MAC addreses。不过,我担心你不能区分,如果他们是Android手机或不。