WlanGetAvailableNetworkList

原文msdn链接地址:https://docs.microsoft.com/zh-cn/windows/desktop/api/wlanapi/nf-wlanapi-wlangetavailablenetworklist

  1 #ifndef UNICODE
  2 #define UNICODE
  3 #endif
  4 
  5 #include <windows.h>
  6 #include <wlanapi.h>
  7 #include <objbase.h>
  8 #include <wtypes.h>
  9 
 10 #include <stdio.h>
 11 #include <stdlib.h>
 12 
 13 // Need to link with Wlanapi.lib and Ole32.lib
 14 #pragma comment(lib, "wlanapi.lib")
 15 #pragma comment(lib, "ole32.lib")
 16 
 17 
 18 int wmain()
 19 {
 20 
 21     // Declare and initialize variables.
 22 
 23     HANDLE hClient = NULL;
 24     DWORD dwMaxClient = 2;      //    
 25     DWORD dwCurVersion = 0;
 26     DWORD dwResult = 0;
 27     DWORD dwRetVal = 0;
 28     int iRet = 0;
 29     
 30     WCHAR GuidString[39] = {0};
 31 
 32     unsigned int i, j, k;
 33 
 34     /* variables used for WlanEnumInterfaces  */
 35 
 36     PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
 37     PWLAN_INTERFACE_INFO pIfInfo = NULL;
 38 
 39     PWLAN_AVAILABLE_NETWORK_LIST pBssList = NULL;
 40     PWLAN_AVAILABLE_NETWORK pBssEntry = NULL;
 41     
 42     int iRSSI = 0;
 43 
 44     dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
 45     if (dwResult != ERROR_SUCCESS) {
 46         wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
 47         return 1;
 48         // You can use FormatMessage here to find out why the function failed
 49     }
 50 
 51     dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
 52     if (dwResult != ERROR_SUCCESS) {
 53         wprintf(L"WlanEnumInterfaces failed with error: %u\n", dwResult);
 54         return 1;
 55         // You can use FormatMessage here to find out why the function failed
 56     } else {
 57         wprintf(L"Num Entries: %lu\n", pIfList->dwNumberOfItems);
 58         wprintf(L"Current Index: %lu\n", pIfList->dwIndex);
 59         for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) {
 60             pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
 61             wprintf(L"  Interface Index[%u]:\t %lu\n", i, i);
 62             iRet = StringFromGUID2(pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString, 
 63                 sizeof(GuidString)/sizeof(*GuidString)); 
 64             // For c rather than C++ source code, the above line needs to be
 65             // iRet = StringFromGUID2(&pIfInfo->InterfaceGuid, (LPOLESTR) &GuidString, 
 66             //     sizeof(GuidString)/sizeof(*GuidString)); 
 67             if (iRet == 0)
 68                 wprintf(L"StringFromGUID2 failed\n");
 69             else {
 70                 wprintf(L"  InterfaceGUID[%d]: %ws\n",i, GuidString);
 71             }    
 72             wprintf(L"  Interface Description[%d]: %ws", i, 
 73                 pIfInfo->strInterfaceDescription);
 74             wprintf(L"\n");
 75             wprintf(L"  Interface State[%d]:\t ", i);
 76             switch (pIfInfo->isState) {
 77             case wlan_interface_state_not_ready:
 78                 wprintf(L"Not ready\n");
 79                 break;
 80             case wlan_interface_state_connected:
 81                 wprintf(L"Connected\n");
 82                 break;
 83             case wlan_interface_state_ad_hoc_network_formed:
 84                 wprintf(L"First node in a ad hoc network\n");
 85                 break;
 86             case wlan_interface_state_disconnecting:
 87                 wprintf(L"Disconnecting\n");
 88                 break;
 89             case wlan_interface_state_disconnected:
 90                 wprintf(L"Not connected\n");
 91                 break;
 92             case wlan_interface_state_associating:
 93                 wprintf(L"Attempting to associate with a network\n");
 94                 break;
 95             case wlan_interface_state_discovering:
 96                 wprintf(L"Auto configuration is discovering settings for the network\n");
 97                 break;
 98             case wlan_interface_state_authenticating:
 99                 wprintf(L"In process of authenticating\n");
100                 break;
101             default:
102                 wprintf(L"Unknown state %ld\n", pIfInfo->isState);
103                 break;
104             }
105             wprintf(L"\n");
106 
107             dwResult = WlanGetAvailableNetworkList(hClient,
108                                              &pIfInfo->InterfaceGuid,
109                                              0, 
110                                              NULL, 
111                                              &pBssList);
112 
113             if (dwResult != ERROR_SUCCESS) {
114                 wprintf(L"WlanGetAvailableNetworkList failed with error: %u\n",
115                         dwResult);
116                 dwRetVal = 1;
117                 // You can use FormatMessage to find out why the function failed
118             } else {
119                 wprintf(L"WLAN_AVAILABLE_NETWORK_LIST for this interface\n");
120 
121                 wprintf(L"  Num Entries: %lu\n\n", pBssList->dwNumberOfItems);
122 
123                 for (j = 0; j < pBssList->dwNumberOfItems; j++) {
124                     pBssEntry =
125                         (WLAN_AVAILABLE_NETWORK *) & pBssList->Network[j];
126 
127                     wprintf(L"  Profile Name[%u]:  %ws\n", j, pBssEntry->strProfileName);
128                     
129                     wprintf(L"  SSID[%u]:\t\t ", j);
130                     if (pBssEntry->dot11Ssid.uSSIDLength == 0)
131                         wprintf(L"\n");
132                     else {   
133                         for (k = 0; k < pBssEntry->dot11Ssid.uSSIDLength; k++) {
134                             wprintf(L"%c", (int) pBssEntry->dot11Ssid.ucSSID[k]);
135                         }
136                         wprintf(L"\n");
137                     }
138                         
139                     wprintf(L"  BSS Network type[%u]:\t ", j);
140                     switch (pBssEntry->dot11BssType) {
141                     case dot11_BSS_type_infrastructure   :
142                         wprintf(L"Infrastructure (%u)\n", pBssEntry->dot11BssType);
143                         break;
144                     case dot11_BSS_type_independent:
145                         wprintf(L"Infrastructure (%u)\n", pBssEntry->dot11BssType);
146                         break;
147                     default:
148                         wprintf(L"Other (%lu)\n", pBssEntry->dot11BssType);
149                         break;
150                     }
151                                 
152                     wprintf(L"  Number of BSSIDs[%u]:\t %u\n", j, pBssEntry->uNumberOfBssids);
153 
154                     wprintf(L"  Connectable[%u]:\t ", j);
155                     if (pBssEntry->bNetworkConnectable)
156                         wprintf(L"Yes\n");
157                     else {
158                         wprintf(L"No\n");
159                         wprintf(L"  Not connectable WLAN_REASON_CODE value[%u]:\t %u\n", j, 
160                             pBssEntry->wlanNotConnectableReason);
161                     }        
162 
163                     wprintf(L"  Number of PHY types supported[%u]:\t %u\n", j, pBssEntry->uNumberOfPhyTypes);
164 
165                     if (pBssEntry->wlanSignalQuality == 0)
166                         iRSSI = -100;
167                     else if (pBssEntry->wlanSignalQuality == 100)   
168                         iRSSI = -50;
169                     else
170                         iRSSI = -100 + (pBssEntry->wlanSignalQuality/2);    
171                         
172                     wprintf(L"  Signal Quality[%u]:\t %u (RSSI: %i dBm)\n", j, 
173                         pBssEntry->wlanSignalQuality, iRSSI);
174 
175                     wprintf(L"  Security Enabled[%u]:\t ", j);
176                     if (pBssEntry->bSecurityEnabled)
177                         wprintf(L"Yes\n");
178                     else
179                         wprintf(L"No\n");
180                         
181                     wprintf(L"  Default AuthAlgorithm[%u]: ", j);
182                     switch (pBssEntry->dot11DefaultAuthAlgorithm) {
183                     case DOT11_AUTH_ALGO_80211_OPEN:
184                         wprintf(L"802.11 Open (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
185                         break;
186                     case DOT11_AUTH_ALGO_80211_SHARED_KEY:
187                         wprintf(L"802.11 Shared (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
188                         break;
189                     case DOT11_AUTH_ALGO_WPA:
190                         wprintf(L"WPA (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
191                         break;
192                     case DOT11_AUTH_ALGO_WPA_PSK:
193                         wprintf(L"WPA-PSK (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
194                         break;
195                     case DOT11_AUTH_ALGO_WPA_NONE:
196                         wprintf(L"WPA-None (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
197                         break;
198                     case DOT11_AUTH_ALGO_RSNA:
199                         wprintf(L"RSNA (%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
200                         break;
201                     case DOT11_AUTH_ALGO_RSNA_PSK:
202                         wprintf(L"RSNA with PSK(%u)\n", pBssEntry->dot11DefaultAuthAlgorithm);
203                         break;
204                     default:
205                         wprintf(L"Other (%lu)\n", pBssEntry->dot11DefaultAuthAlgorithm);
206                         break;
207                     }
208                         
209                     wprintf(L"  Default CipherAlgorithm[%u]: ", j);
210                     switch (pBssEntry->dot11DefaultCipherAlgorithm) {
211                     case DOT11_CIPHER_ALGO_NONE:
212                         wprintf(L"None (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
213                         break;
214                     case DOT11_CIPHER_ALGO_WEP40:
215                         wprintf(L"WEP-40 (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
216                         break;
217                     case DOT11_CIPHER_ALGO_TKIP:
218                         wprintf(L"TKIP (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
219                         break;
220                     case DOT11_CIPHER_ALGO_CCMP:
221                         wprintf(L"CCMP (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
222                         break;
223                     case DOT11_CIPHER_ALGO_WEP104:
224                         wprintf(L"WEP-104 (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
225                         break;
226                     case DOT11_CIPHER_ALGO_WEP:
227                         wprintf(L"WEP (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
228                         break;
229                     default:
230                         wprintf(L"Other (0x%x)\n", pBssEntry->dot11DefaultCipherAlgorithm);
231                         break;
232                     }
233 
234                     wprintf(L"  Flags[%u]:\t 0x%x", j, pBssEntry->dwFlags);
235                     if (pBssEntry->dwFlags) {
236                         if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
237                             wprintf(L" - Currently connected");
238                         if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
239                             wprintf(L" - Has profile");
240                     }   
241                     wprintf(L"\n");
242                     
243                     wprintf(L"\n");
244                 }
245             }
246         }
247 
248     }
249     if (pBssList != NULL) {
250         WlanFreeMemory(pBssList);
251         pBssList = NULL;
252     }
253 
254     if (pIfList != NULL) {
255         WlanFreeMemory(pIfList);
256         pIfList = NULL;
257     }
258 
259     return dwRetVal;
260 }

 

转载于:https://www.cnblogs.com/wuyuan2011woaini/p/10444422.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值