如何获取连接到wifi热点的客户端设备详细信息? [英] How to get the client device details which is connected to wifi hotspot?

查看:43
本文介绍了如何获取连接到wifi热点的客户端设备详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 android 应用程序中以编程方式将不同设备与 wifi 热点 AP 连接,如何以编程方式检测客户端连接和断开连接以及到 wifi 热点 AP?Android API 中是否有任何回调事件来提供有关单个设备的连接或断开连接事件的信息?提前致谢.

I am connecting different devices with wifi hotspot AP programatically in my android app, How can i detect the clients being connected and disconnected and to the wifi hotspot AP Programmatically ? Is there any callback event in Android API to give information regarding the connection or disconnection events of individual devices ? Thanks in advance.

推荐答案

遗憾的是没有公共 API 来提供有关此的信息...但是您可以读取/proc/net/arp 文件并查看连接到您的接入点的客户端.

Unfortunately there is no public API to give information about this... But you can read /proc/net/arp file and see the clients connected to your Access Point.

/proc/net/arp 文件有 6 个字段:IP 地址硬件类型标志硬件地址面具设备

/proc/net/arp file have 6 fields: IP address, HW type, Flags, HW address, Mask and Device

问题是当客户端断开连接时,因为它不会从文件中消失.一个解决方案可能是对每个客户端执行 ping 并等待响应,但对我来说这不是一个好的解决方案,因为有些客户端不响应 ping.如果你喜欢这个解决方案,请在 GitHub 上查看这个项目 --> https://github.com/nickrussler/Android-Wifi-Hotspot-Manager-Class/tree/master/src/com/whitebyte

The problem is when a client get disconnected, because it doesn't disappear from the file. A solution may be to do ping to every client and wait for response, but for me this isn't a good solution because some clients don't respond to ping. If you like this solution check this project on GitHub --> https://github.com/nickrussler/Android-Wifi-Hotspot-Manager-Class/tree/master/src/com/whitebyte

我所做的是:读取/proc/net/arp 并检查 FLAGS 字段,当值为 0x2 时,站已连接,0x0 已断开连接,但要刷新此字段,我需要不时清除ARP缓存,我用这个命令做到了:ip neigh flush all

What i have did is: read /proc/net/arp and check the FLAGS field, when the value is 0x2 the station is connected and 0x0 is disconnected, but to refresh this field I need to clear ARP cache from time to time, and i did it with this command: ip neigh flush all

希望能帮到你

这篇关于如何获取连接到wifi热点的客户端设备详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆