如何获取wifi信号强度

2020-06-02 社会 102阅读
现在WIFI热点越来越多,以下是通过C++ & wlanapi来获取当前可检测到的SID的信号强度。
void WifiQual()
{
DWORD dwError = ERROR_SUCCESS;
DWORD dwNegotiatedVersion;
HANDLE hClientHandle = NULL;

dwError = WlanOpenHandle(WLAN_API_VERSION_1_0, NULL, &dwNegotiatedVersion, &hClientHandle);
if (dwError != ERROR_SUCCESS)
{
wprintf(L"WlanOpenHandle error %d\n", dwError);
goto _ret;
}

PWLAN_INTERFACE_INFO_LIST pInterfaceList = NULL;
dwError = WlanEnumInterfaces(hClientHandle, NULL,&pInterfaceList);
if ( dwError != ERROR_SUCCESS )
{
wprintf(L"WlanEnumInterfaces error %d\n", dwError);
goto _ret;
}

GUID &guid = pInterfaceList->InterfaceInfo[0].InterfaceGuid;
PWLAN_AVAILABLE_NETWORK_LIST pWLAN_AVAILABLE_NETWORK_LIST = NULL;

dwError = WlanGetAvailableNetworkList(hClientHandle, &guid,
WLAN_AVAILABLE_NETWORK_INCLUDE_ALL_MANUAL_HIDDEN_PROFILES,
NULL, &pWLAN_AVAILABLE_NETWORK_LIST);
if (dwError != ERROR_SUCCESS)
{
wprintf(L"WlanGetAvailableNetworkList error %d\n", dwError);
goto _ret;
}
if (pWLAN_AVAILABLE_NETWORK_LIST->dwNumberOfItems > 0)
{
wchar_t sz[256] = { 0 };
for (DWORD i = 0; i < pWLAN_AVAILABLE_NETWORK_LIST->dwNumberOfItems; i++)
{
WLAN_AVAILABLE_NETWORK wlanAN = pWLAN_AVAILABLE_NETWORK_LIST[0].Network[i];

printf("%s:%d\n", wlanAN.dot11Ssid.ucSSID, wlanAN.wlanSignalQuality);
}
}
_ret: //释放资源
if(hClientHandle)
WlanCloseHandle(hClientHandle, NULL);
if(pInterfaceList)
WlanFreeMemory(pInterfaceList);
if(pWLAN_AVAILABLE_NETWORK_LIST)
WlanFreeMemory(pWLAN_AVAILABLE_NETWORK_LIST);
}
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com