windows – 用于获取信号强度的WLAN API
发布时间:2020-12-13 20:35:44 所属栏目:Windows 来源:网络整理
导读:我正在使用WLAN Api,即WlanGetAvailableNetworkList()来获取无线局域网调制解调器/ USB数据卡的信号强度.如果有人有一些示例代码示例或某些信息,请发送给我. 如果您使用的是Python,则有 sample code here. 如果您使用C,the documentation提供了一个很好的例
我正在使用WLAN Api,即WlanGetAvailableNetworkList()来获取无线局域网调制解调器/ USB数据卡的信号强度.如果有人有一些示例代码示例或某些信息,请发送给我.
如果您使用的是Python,则有
sample code here.
如果您使用C,the documentation提供了一个很好的例子: #define UNICODE #include <windows.h> #include <wlanapi.h> #include <objbase.h> #include <wtypes.h> #include <stdio.h> #include <stdlib.h> // Need to link with Wlanapi.lib and Ole32.lib #pragma comment(lib,"wlanapi.lib") #pragma comment(lib,"ole32.lib") int wmain() { // Declare and initialize variables. HANDLE hClient = NULL; DWORD dwMaxClient = 2; // DWORD dwCurVersion = 0; DWORD dwResult = 0; DWORD dwRetVal = 0; int iRet = 0; WCHAR GuidString[39] = {0}; unsigned int i,j,k; /* variables used for WlanEnumInterfaces */ PWLAN_INTERFACE_INFO_LIST pIfList = NULL; PWLAN_INTERFACE_INFO pIfInfo = NULL; PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL; PWLAN_AVAILABLE_NETWORK pBssEntry = NULL; dwResult = WlanOpenHandle(dwMaxClient,NULL,&dwCurVersion,&hClient); if (dwResult != ERROR_SUCCESS) { wprintf(L"WlanOpenHandle failed with error: %un",dwResult); return 1; // You can use FormatMessage here to find out why the function failed } dwResult = WlanEnumInterfaces(hClient,&pIfList); if (dwResult != ERROR_SUCCESS) { wprintf(L"WlanEnumInterfaces failed with error: %un",dwResult); return 1; // You can use FormatMessage here to find out why the function failed } else { wprintf(L"Num Entries: %lun",pIfList->dwNumberOfItems); wprintf(L"Current Index: %lun",pIfList->dwIndex); for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) { pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i]; wprintf(L" Interface Index[%u]:t %lun",i,i); iRet = StringFromGUID2(pIfInfo->InterfaceGuid,(LPOLESTR) &GuidString,sizeof(GuidString)/sizeof(*GuidString)); // For c rather than C++ source code,the above line needs to be // iRet = StringFromGUID2(&pIfInfo->InterfaceGuid,// sizeof(GuidString)/sizeof(*GuidString)); if (iRet == 0) wprintf(L"StringFromGUID2 failedn"); else { wprintf(L" InterfaceGUID[%d]: %wsn",GuidString); } wprintf(L" Interface Description[%d]: %ws",pIfInfo->strInterfaceDescription); wprintf(L"n"); wprintf(L" Interface State[%d]:t ",i); switch (pIfInfo->isState) { case wlan_interface_state_not_ready: wprintf(L"Not readyn"); break; case wlan_interface_state_connected: wprintf(L"Connectedn"); break; case wlan_interface_state_ad_hoc_network_formed: wprintf(L"First node in a ad hoc networkn"); break; case wlan_interface_state_disconnecting: wprintf(L"Disconnectingn"); break; case wlan_interface_state_disconnected: wprintf(L"Not connectedn"); break; case wlan_interface_state_associating: wprintf(L"Attempting to associate with a networkn"); break; case wlan_interface_state_discovering: wprintf(L"Auto configuration is discovering settings for the networkn"); break; case wlan_interface_state_authenticating: wprintf(L"In process of authenticatingn"); break; default: wprintf(L"Unknown state %ldn",pIfInfo->isState); break; } wprintf(L"n"); dwResult = WlanGetAvailableNetworkList(hClient,&pIfInfo->InterfaceGuid,&pBssList); if (dwResult != ERROR_SUCCESS) { wprintf(L"WlanGetAvailableNetworkList failed with error: %un",dwResult); dwRetVal = 1; // You can use FormatMessage to find out why the function failed } else { wprintf(L"WLAN_AVAILABLE_NETWORK_LIST for this interfacen"); wprintf(L" Num Entries: %lunn",pBssList->dwNumberOfItems); for (j = 0; j < pBssList->dwNumberOfItems; j++) { pBssEntry = (WLAN_AVAILABLE_NETWORK *) & pBssList->Network[j]; wprintf(L" Profile Name[%u]: %wsn",pBssEntry->strProfileName); wprintf(L" SSID[%u]:tt ",j); if (pBssEntry->dot11Ssid.uSSIDLength == 0) wprintf(L"n"); else { for (k = 0; k < pBssEntry->dot11Ssid.uSSIDLength; k++) { wprintf(L"%c",(int) pBssEntry->dot11Ssid.ucSSID[k]); } wprintf(L"n"); } wprintf(L" BSS Network type[%u]:t ",j); switch (pBssEntry->dot11BssType) { case dot11_BSS_type_infrastructure : wprintf(L"Infrastructure (%u)n",pBssEntry->dot11BssType); break; case dot11_BSS_type_independent: wprintf(L"Infrastructure (%u)n",pBssEntry->dot11BssType); break; default: wprintf(L"Other (%lu)n",pBssEntry->dot11BssType); break; } wprintf(L" Number of BSSIDs[%u]:t %un",pBssEntry->uNumberOfBssids); wprintf(L" Connectable[%u]:t ",j); if (pBssEntry->bNetworkConnectable) wprintf(L"Yesn"); else wprintf(L"Non"); wprintf(L" Signal Quality[%u]:t %un",pBssEntry->wlanSignalQuality); wprintf(L" Security Enabled[%u]:t ",j); if (pBssEntry->bSecurityEnabled) wprintf(L"Yesn"); else wprintf(L"Non"); wprintf(L" Default AuthAlgorithm[%u]: ",j); switch (pBssEntry->dot11DefaultAuthAlgorithm) { case DOT11_AUTH_ALGO_80211_OPEN: wprintf(L"802.11 Open (%u)n",pBssEntry->dot11DefaultAuthAlgorithm); break; case DOT11_AUTH_ALGO_80211_SHARED_KEY: wprintf(L"802.11 Shared (%u)n",pBssEntry->dot11DefaultAuthAlgorithm); break; case DOT11_AUTH_ALGO_WPA: wprintf(L"WPA (%u)n",pBssEntry->dot11DefaultAuthAlgorithm); break; case DOT11_AUTH_ALGO_WPA_PSK: wprintf(L"WPA-PSK (%u)n",pBssEntry->dot11DefaultAuthAlgorithm); break; case DOT11_AUTH_ALGO_WPA_NONE: wprintf(L"WPA-None (%u)n",pBssEntry->dot11DefaultAuthAlgorithm); break; case DOT11_AUTH_ALGO_RSNA: wprintf(L"RSNA (%u)n",pBssEntry->dot11DefaultAuthAlgorithm); break; case DOT11_AUTH_ALGO_RSNA_PSK: wprintf(L"RSNA with PSK(%u)n",pBssEntry->dot11DefaultAuthAlgorithm); break; default: wprintf(L"Other (%lu)n",pBssEntry->dot11DefaultAuthAlgorithm); break; } wprintf(L" Default CipherAlgorithm[%u]: ",j); switch (pBssEntry->dot11DefaultCipherAlgorithm) { case DOT11_CIPHER_ALGO_NONE: wprintf(L"None (0x%x)n",pBssEntry->dot11DefaultCipherAlgorithm); break; case DOT11_CIPHER_ALGO_WEP40: wprintf(L"WEP-40 (0x%x)n",pBssEntry->dot11DefaultCipherAlgorithm); break; case DOT11_CIPHER_ALGO_TKIP: wprintf(L"TKIP (0x%x)n",pBssEntry->dot11DefaultCipherAlgorithm); break; case DOT11_CIPHER_ALGO_CCMP: wprintf(L"CCMP (0x%x)n",pBssEntry->dot11DefaultCipherAlgorithm); break; case DOT11_CIPHER_ALGO_WEP104: wprintf(L"WEP-104 (0x%x)n",pBssEntry->dot11DefaultCipherAlgorithm); break; case DOT11_CIPHER_ALGO_WEP: wprintf(L"WEP (0x%x)n",pBssEntry->dot11DefaultCipherAlgorithm); break; default: wprintf(L"Other (0x%x)n",pBssEntry->dot11DefaultCipherAlgorithm); break; } wprintf(L"n"); } } } } if (pBssList != NULL) { WlanFreeMemory(pBssList); pBssList = NULL; } if (pIfList != NULL) { WlanFreeMemory(pIfList); pIfList = NULL; } return dwRetVal; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows – Active Directory的负载测试工具?
- windows-8 – Windows Phone 8 SDK可以安装在Windows 8 32位
- 升级Windows Server并保留UNC路径?
- 格式化字符串溢出实验
- 在Windows / OSX / Linux上为Python中的图标添加徽章
- Windows&Appium&Java&Python自动化测试-配置开
- 批处理文件 – chcp 65001和.bat文件
- 配置Windows DNS解析程序缓存
- .net – Windows / Linux之间的Unison同步在传输过程中随机
- win 10 如何关闭自动更新