WIFI信号强度获取

现在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);
}


供大家参考,下一步想通过在手机上实现来检测wifi信号;

你可能感兴趣的:(Windows)