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; } }