Details of connected users to mobile hotspot

为君一笑 提交于 2020-01-13 06:47:12

问题


If I've enabled Wi-Fi Hotspot in my android phone and 2 other android phones are connected to my Hotspot, then how can I distinguish between each phone?

Does my phone distinguish between the different phones using IEMI numbers or something else?


回答1:


1) You can use BroadcastReciever "android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED" to detect client connection. In your AndroidManifest:

<receiver
        android:name=".WiFiConnectionReciever"
        android:enabled="true"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED" />
        </intent-filter>
    </receiver>

and in your activity:

IntentFilter mIntentFilter = new IntentFilter();
  mIntentFilter.addAction("android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED");
                    rcv = new WiFiConnectionReciever();
                    registerReceiver(rcv,
                            mIntentFilter);

2) On other hand please check this answer too: https://stackoverflow.com/a/21545389/1384010

Hope one of above methods will help you !!




回答2:


The IMEI does not take place in the association to the AP (in this case, your Android phone serving as a hotspot), which doesn't even know that the stations asking to connect are phones. The association takes place via probe request / probe response at the Layer 2 level (i.e. the MAC address).

Here's the whole association process in detail (from https://documentation.meraki.com/MR/WiFi_Basics_and_Best_Practices/802.11_Association_process_explained):

Access points are bridges that bridge traffic between mobile stations and other devices on the network. Before a mobile station can send traffic through an AP, it must be in the appropriate connection state.

The three 802.11 connection states are:

  • Not authenticated or associated.
  • Authenticated but not yet associated.
  • Authenticated and associated.

A mobile station must be in an authenticated and associated state before bridging will occur.

The mobile station and AP will exchange a series of 802.11 management frames in order to get to an authenticated and associated state.

A mobile station starts out as not authenticated and associated.

  1. A mobile station sends probe requests to discover 802.11 networks within its proximity. Probe requests advertise the mobile stations supported data rates and 802.11 capabilities such as 802.11n. Because the probe request is sent from the mobile station to the destination layer-2 address and BSSID of ff:ff:ff:ff:ff:ff all AP's that receive it will respond.

  2. APs receiving the probe request check to see if the mobile station has at least one common supported data rate. If they have compatible data rates, a probe response is sent advertising the SSID (wireless network name), supported data rates, encryption types if required, and other 802.11 capabilities of the AP.

    A mobile station chooses compatible networks from the probe responses it receives. Compatibility could be based on encryption type. Once compatible networks are discovered the mobile station will attempt low-level 802.11 authentication with compatible APs. Keep in mind that 802.11 authentication is not the same as WPA2 or 802.1X authentication mechanisms which occur after a mobile station is authenticated and associated. Originally 802.11 authentication frames were designed for WEP encryption however this security scheme has been proven to be insecure and therefore deprecated. Because of this 802.11 authentication frames are open and almost always succeed.

  3. A mobile station sends a low-level 802.11 authentication frame to an AP setting the authentication to open and the sequence to 0x0001.

  4. The AP receives the authentication frame and responds to the mobile station with authentication frame set to open indicating a sequence of 0x0002.

    If an AP receives any frame other than a authentication or probe request from a mobile station that is not authenticated it will respond with a deauthentication frame placing the mobile into an unauthenticated an unassociated state. The station will have to begin the association process from the low level authentication step. At this point the mobile station is authenticated but not yet associated. Some 802.11 capabilities allow a mobile station to low-level authenticate to multiple APs. This speeds up the association process when moving between APs. A mobile station can be 802.11 authenticated to multiple APs however it can only be actively associated and transferring data through a single AP at a time.

  5. Once a mobile station determines which AP it would like to associate to, it will send an association request to that AP. The association request contains chosen encryption types if required and other compatible 802.11 capabilities. If an AP receives a frame from a mobile station that is authenticated but not yet associated, it will respond with a disassociation frame placing the mobile into an authenticated but unassociated state.

  6. If the elements in the association request match the capabilties of the AP, the AP will create an Association ID for the mobile station and respond with an association response with a success message granting network access to the mobile station.

  7. Now the mobile station is successfully associated to the AP and data transfer can begin.

Note: If WPA/WPA2 or 802.1X authentication is required on the wireless network, the mobile station will not be able to send data until dynamic keying and authentication have taken place after the 802.11 Association is complete.




回答3:


when a device connects to your hotspot, hotspot's DHCP server recognize these devices by thier MAC addresses and allocate one or several IP's to the devices and store this data(MAC address and allocated IP) in "/proc/net/arp"

you can get this latest data by using-

Runtime.exec("ip -s -s neigh flush all")


来源:https://stackoverflow.com/questions/33983214/details-of-connected-users-to-mobile-hotspot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!