[英]Detecting android devices connected to Wifi
我想创建一个连接到Wifi网络的android应用程序,比如网络SSID =“ABC”。假设它连接到Wifi ABC。 连接到ABC后,我希望我的应用程序显示连接到同一wifi ABC网络的所有Android设备的ips。 我怎样才能实现这一目标? 谢谢
在手机上查看文件:/ proc / net / arp。
它具有连接到同一网络的所有其他设备的IP和MAC地址。 但是,我担心如果他们是Android手机,你将无法区分。
您将需要使用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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.