1、获取Mac地址

//WiFi通知回调
        private WlanApi.WLAN_NOTIFICATION_CALLBACK _notificationCallback;

this._notificationCallback = new WlanApi.WLAN_NOTIFICATION_CALLBACK(this.OnNotification);
            WLAN_NOTIFICATION_SOURCE notifSource;
            WiFiApiUtils.Throw_On_Win32_Error(WlanApi.WlanRegisterNotification(this._WlanHandle, WLAN_NOTIFICATION_SOURCE.All, true, this._notificationCallback, IntPtr.Zero, IntPtr.Zero, out notifSource));


        protected void OnNotification(ref WLAN_NOTIFICATION_DATA notifData, IntPtr context)
        {
            switch (notifData.notificationCode)
            {
                case (int)WLAN_HOSTED_NETWORK_NOTIFICATION_CODE.wlan_hosted_network_state_change:   //网络状态改变时
                    break;
                    
                case (int)WLAN_HOSTED_NETWORK_NOTIFICATION_CODE.wlan_hosted_network_peer_state_change:  //客户端接入或退出WiFi时,记录或删除该客户端的mac地址等信息

                    if (notifData.dataSize > 0 && notifData.dataPtr != IntPtr.Zero)
                    {
                        WLAN_HOSTED_NETWORK_DATA_PEER_STATE_CHANGE pPeerStateChange = (WLAN_HOSTED_NETWORK_DATA_PEER_STATE_CHANGE)Marshal.PtrToStructure(notifData.dataPtr, typeof(WLAN_HOSTED_NETWORK_DATA_PEER_STATE_CHANGE));

                        if (pPeerStateChange.NewState.PeerAuthState == WLAN_HOSTED_NETWORK_PEER_AUTH_STATE.wlan_hosted_network_peer_state_authenticated)
                        {
                            // Station joined the hosted network
                            this.onJoinWiFi(pPeerStateChange.NewState);
                        }
                        else if (pPeerStateChange.NewState.PeerAuthState == WLAN_HOSTED_NETWORK_PEER_AUTH_STATE.wlan_hosted_network_peer_state_invalid)
                        {
                            // Station left the hosted network
                            this.onLeaveWiFi(pPeerStateChange.NewState);
                        }
                        else
                        {
                            // Authentication state changed
                        }
                    }

                    break;
            }


        }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2021-11-29
  • 2022-12-23
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2021-08-02
  • 2021-12-18
  • 2021-12-27
  • 2021-10-11
  • 2021-12-01
相关资源
相似解决方案