本文转自:http://blog.csdn.net/freeape/article/details/45954309
实现功能
无线网卡列表
无线热点扫面
无线连接(有密码,配置文件连接方式)
无线断开
重命名本地无线名(两种方式)
删除无线配置文件
开启和关闭无线网卡
Native Wifi 简介
是提供给软件开发者来开发windows 无线管理的一系列API。编程人员可以通过这些函数来进行相关的无线管理,当然我们还可以通过netsh终端命令来管理,这对于非编程人员就可以简单的实现,具体可以查阅相关资料去了解。
API如下:
- WLAN_NOTIFICATION_CALLBACK
- WlanAllocateMemory
- WlanCloseHandle
- WlanConnect
- WlanDeleteProfile
- WlanDisconnect
- WlanEnumInterfaces
- WlanExtractPsdIEDataList
- WlanFreeMemory
- WlanGetAvailableNetworkList
- WlanGetFilterList
- WlanGetInterfaceCapability
- WlanGetNetworkBssList
- WlanGetProfile
- WlanGetProfileCustomUserData
- WlanGetProfileList
- WlanGetSecuritySettings
- WlanHostedNetworkForceStart
- WlanHostedNetworkForceStop
- WlanHostedNetworkInitSettings
- WlanHostedNetworkQueryProperty
- WlanHostedNetworkQuerySecondaryKey
- WlanHostedNetworkQueryStatus
- WlanHostedNetworkRefreshSecuritySettings
- WlanHostedNetworkSetProperty
- WlanHostedNetworkSetSecondaryKey
- WlanHostedNetworkStartUsing
- WlanHostedNetworkStopUsing
- WlanIhvControl
- WlanOpenHandle
- WlanQueryAutoConfigParameter
- WlanQueryInterface
- WlanReasonCodeToString
- WlanRegisterNotification
- WlanRegisterVirtualStationNotification
- WlanRenameProfile
- WlanSaveTemporaryProfile
- WlanScan
- WlanSetAutoConfigParameter
- WlanSetFilterList
- WlanSetInterface
- WlanSetProfile
- WlanSetProfileCustomUserData
- WlanSetProfileEapUserData
- WlanSetProfileEapXmlUserData
- WlanSetProfileList
- WlanSetProfilePosition
- WlanSetPsdIeDataList
- WlanSetSecuritySettings
无线的连接相关知识
从windows的无线网络属性设置窗口来对比,在API编程中,同样有个配置文件来设置这些属性的,那就是profile文件,通过编写xml文件来设置相关属性。
WLAN_profile Schema Elements [xml配置文件编写格式]:
- WLANProfile
- name (WLANProfile)
- SSIDConfig (WLANProfile)
- connectionType (WLANProfile)
- connectionMode (WLANProfile)
- autoSwitch (WLANProfile)
- MSM (WLANProfile)
- IHV (WLANProfile)
Wireless Profile Samples[无线配置文件例程]
- Bootstrap Profile Sample
- FIPS Profile Sample
- Non-Broadcast Profile Sample
- Single Sign-On Profile Sample
- WPA-Enterprise with PEAP-MSCHAPv2 Profile Sample
- WPA-Enterprise with TLS Profile Sample
- WPA-Personal Profile Sample
- WPA2-Enterprise with PEAP-MSCHAPv2 Profile Sample
- WPA2-Enterprise with TLS Profile Sample
- WPA2-Personal Profile Sample
例如常见的路由器,安全类型为WPA2-PSK的xml配置文件如下(有密码):
<?xml version="1.0" encoding="US-ASCII"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>SampleWPA2PSK</name>
<SSIDConfig>
<SSID>
<name>SampleWPA2PSK</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<autoSwitch>false</autoSwitch>
<MSM>
<security>
<authEncryption>
<authentication>WPA2PSK</authentication>
<encryption>AES</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial> <!-- insert key here --> </keyMaterial></sharedKey>
</security>
</MSM></WLANProfile>
注:
【加密类型设置】<encryption>AES</encryption>
【安全类型设置】<authentication>WPAPSK</authentication>
具体功能编程实现(QTCtreator 5.xx)
Value Description open Open 802.11 authentication. shared Shared 802.11 authentication. WPA WPA-Enterprise 802.11 authentication. WPAPSK WPA-Personal 802.11 authentication. WPA2 WPA2-Enterprise 802.11 authentication. WPA2PSK WPA2-Personal 802.11 authentication.
.pro文件
LIBS+=$$quote(E:/qt/2015-4-9/WlanGetProfileTest/WlanGetProfileTest/lib/wlanapi.lib)
LIBS+=$$quote(E:/qt/2015-4-9/WlanGetProfileTest/WlanGetProfileTest/lib/OLE32.lib)
包含头文件
#include<windows.h>#include<wlanapi.h>