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

 #ifndef UNICODE
#define UNICODE
#endif #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 = ; //
DWORD dwCurVersion = ;
DWORD dwResult = ;
DWORD dwRetVal = ;
int iRet = ; WCHAR GuidString[] = {}; 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; int iRSSI = ; dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
return ;
// You can use FormatMessage here to find out why the function failed
} dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanEnumInterfaces failed with error: %u\n", dwResult);
return ;
// You can use FormatMessage here to find out why the function failed
} else {
wprintf(L"Num Entries: %lu\n", pIfList->dwNumberOfItems);
wprintf(L"Current Index: %lu\n", pIfList->dwIndex);
for (i = ; i < (int) pIfList->dwNumberOfItems; i++) {
pIfInfo = (WLAN_INTERFACE_INFO *) &pIfList->InterfaceInfo[i];
wprintf(L" Interface Index[%u]:\t %lu\n", 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, (LPOLESTR) &GuidString,
// sizeof(GuidString)/sizeof(*GuidString));
if (iRet == )
wprintf(L"StringFromGUID2 failed\n");
else {
wprintf(L" InterfaceGUID[%d]: %ws\n",i, GuidString);
}
wprintf(L" Interface Description[%d]: %ws", i,
pIfInfo->strInterfaceDescription);
wprintf(L"\n");
wprintf(L" Interface State[%d]:\t ", i);
switch (pIfInfo->isState) {
case wlan_interface_state_not_ready:
wprintf(L"Not ready\n");
break;
case wlan_interface_state_connected:
wprintf(L"Connected\n");
break;
case wlan_interface_state_ad_hoc_network_formed:
wprintf(L"First node in a ad hoc network\n");
break;
case wlan_interface_state_disconnecting:
wprintf(L"Disconnecting\n");
break;
case wlan_interface_state_disconnected:
wprintf(L"Not connected\n");
break;
case wlan_interface_state_associating:
wprintf(L"Attempting to associate with a network\n");
break;
case wlan_interface_state_discovering:
wprintf(L"Auto configuration is discovering settings for the network\n");
break;
case wlan_interface_state_authenticating:
wprintf(L"In process of authenticating\n");
break;
default:
wprintf(L"Unknown state %ld\n", pIfInfo->isState);
break;
}
wprintf(L"\n"); dwResult = WlanGetAvailableNetworkList(hClient,
&pIfInfo->InterfaceGuid,
,
NULL,
&pBssList); if (dwResult != ERROR_SUCCESS) {
wprintf(L"WlanGetAvailableNetworkList failed with error: %u\n",
dwResult);
dwRetVal = ;
// You can use FormatMessage to find out why the function failed
} else {
wprintf(L"WLAN_AVAILABLE_NETWORK_LIST for this interface\n"); wprintf(L" Num Entries: %lu\n\n", pBssList->dwNumberOfItems); for (j = ; j < pBssList->dwNumberOfItems; j++) {
pBssEntry =
(WLAN_AVAILABLE_NETWORK *) & pBssList->Network[j]; wprintf(L" Profile Name[%u]: %ws\n", j, pBssEntry->strProfileName); wprintf(L" SSID[%u]:\t\t ", j);
if (pBssEntry->dot11Ssid.uSSIDLength == )
wprintf(L"\n");
else {
for (k = ; 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 %u\n", j, pBssEntry->uNumberOfBssids); wprintf(L" Connectable[%u]:\t ", j);
if (pBssEntry->bNetworkConnectable)
wprintf(L"Yes\n");
else {
wprintf(L"No\n");
wprintf(L" Not connectable WLAN_REASON_CODE value[%u]:\t %u\n", j,
pBssEntry->wlanNotConnectableReason);
} wprintf(L" Number of PHY types supported[%u]:\t %u\n", j, pBssEntry->uNumberOfPhyTypes); if (pBssEntry->wlanSignalQuality == )
iRSSI = -;
else if (pBssEntry->wlanSignalQuality == )
iRSSI = -;
else
iRSSI = - + (pBssEntry->wlanSignalQuality/); wprintf(L" Signal Quality[%u]:\t %u (RSSI: %i dBm)\n", j,
pBssEntry->wlanSignalQuality, iRSSI); wprintf(L" Security Enabled[%u]:\t ", j);
if (pBssEntry->bSecurityEnabled)
wprintf(L"Yes\n");
else
wprintf(L"No\n"); 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" Flags[%u]:\t 0x%x", j, pBssEntry->dwFlags);
if (pBssEntry->dwFlags) {
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
wprintf(L" - Currently connected");
if (pBssEntry->dwFlags & WLAN_AVAILABLE_NETWORK_CONNECTED)
wprintf(L" - Has profile");
}
wprintf(L"\n"); wprintf(L"\n");
}
}
} }
if (pBssList != NULL) {
WlanFreeMemory(pBssList);
pBssList = NULL;
} if (pIfList != NULL) {
WlanFreeMemory(pIfList);
pIfList = NULL;
} return dwRetVal;
}

WlanGetAvailableNetworkList的更多相关文章

  1. Native wifi API使用

    写于博客园,自己迁过来: 一.WlanOpenHandle打开一个客户端句柄 DWORD WINAPI WlanOpenHandle( __in DWORD dwClientVersion, __re ...

  2. c# 如何使用wlanapi连接电脑到wifi

    http://www.codeproject.com/Articles/72105/Manage-WiFi-with-Native-API-WIFI-on-Windows-XP-SP Introduc ...

  3. windows主机防护

    Netsh命令-修改网络IP设置 网络管理相关函数 Windows用户相关操作 SID(安全标识符) 策略其他说明 主机防护设置 命令行添加防火墙 防火墙规则 使用SetupDI* API列举系统中的 ...

  4. C++操作Windows WIFI

    原文链接地址:https://blog.csdn.net/just_do_1122/article/details/78031024 实现功能     无线网卡列表     无线热点扫面     无线 ...

  5. 在C++程序中开启和禁用Windows设备的无线网卡的方法

    原文链接地址:https://www.jb51.net/article/81340.htm 1.列出当前网卡:SetupDiEnumDeviceInfo 2.找出当前无线网卡的名字(用natvie w ...

  6. QT---Native Wifi functions 应用(WiFi有密码连接)

    实现功能     无线网卡列表     无线热点扫面     无线连接(有密码,配置文件连接方式)     无线断开     重命名本地无线名(两种方式)     删除无线配置文件     开启和关闭 ...

随机推荐

  1. 堆中的路径(MOOC)

    将一系列给定数字插入一个初始为空的小顶堆H[].随后对任意给定的下标i,打印从H[i]到根结点的路径. 输入格式: 每组测试第1行包含2个正整数N和M(≤),分别是插入元素的个数.以及需要打印的路径条 ...

  2. PHP核心技术——魔术方法

    魔术方法: 魔术方法是以两个下画线开头.具有特殊作用的一些方法,可以看做PHP的"语法糖". set和get方法: class Account{ private $user=1; ...

  3. 换Mac了,迈入了终端的大门

    多终端其实本质和多线程一样,所有终端其实都共享着同一个内存只不过不同终端对共享内存不同部分的权限不同罢了所以对终端的数量必须要有限制 我这里开启了四个线程,很明显四个线程都在跑同一个内存而且四个线程都 ...

  4. 高可用Kubernetes集群-11. 部署kube-dns

    参考文档: Github介绍:https://github.com/kubernetes/dns Github yaml文件:https://github.com/kubernetes/kuberne ...

  5. CentOS7.2 部署Haproxy 1.7.2

    原文发表于cu:2017-03-16 参考文档: haproxy:http://www.haproxy.org/ 本文涉及haproxy的安装,并做简单配置. 一.环境准备 1. 操作系统 CentO ...

  6. 技本功丨收藏!斜杠青年与你共探微信小程序云开发(下篇)

    2019年2月26日,人们为了一个杯子疯了一天. 星巴克猫爪杯,一场已经与猫无关了的“圣杯战争“.网上的倒卖价格,已炒至近千元! 求而不得,舍而不能,得而不惜.这是人最大的悲哀... 所以,请珍惜以下 ...

  7. 【视频编解码·学习笔记】4. H.264的码流封装格式 & 提取NAL有效数据

    一.码流封装格式简单介绍: H.264的语法元素进行编码后,生成的输出数据都封装为NAL Unit进行传递,多个NAL Unit的数据组合在一起形成总的输出码流.对于不同的应用场景,NAL规定了一种通 ...

  8. leetcode个人题解——#34 Find First and Last Position of Element in Sorted Array

    思路:先二分查找到一个和target相同的元素,然后再左边二分查找左边界,右边二分查找有边界. class Solution { public: , end = -; int ends; int lS ...

  9. 安装好Oracle Client以后没有tnsnames.ora文件

    安装好Oracle Client以后没有tnsnames.ora文件 安装完Oracle Client以后,发现相应目录中没有tnsnames.ora文件,其实只要手动建立一个就可以了.在 oracl ...

  10. The Bits (思维+找规律)

    Description Rudolf is on his way to the castle. Before getting into the castle, the security staff a ...