C++操作Windows WIFI
原文链接地址:https://blog.csdn.net/just_do_1122/article/details/78031024
- 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
- WlanUIEditProfile

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
<?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>
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>
程序实现(终端打印信息)
#include<windows.h>
#include<wlanapi.h>
#include<string>
#include<stdio.h> //无线连接状态
intlistenStatus()
{
HANDLEhClient=NULL;
DWORDdwMaxClient=;
DWORDdwCurVersion=;
DWORDdwResult=;
intiRet=;
WCHARGuidString[]={};
//ListenthestatusoftheAPyouconnected.
while(){
Sleep();
PWLAN_INTERFACE_INFO_LISTpIfList=NULL;
PWLAN_INTERFACE_INFOpIfInfo=NULL; dwResult=WlanOpenHandle(dwMaxClient,NULL,&dwCurVersion,&hClient);
if(dwResult!=ERROR_SUCCESS){
wprintf(L"WlanOpenHandlefailedwitherror:%u\n",dwResult);
return1;
}
//获取无线网卡列表
dwResult=WlanEnumInterfaces(hClient,NULL,&pIfList);
if(dwResult!=ERROR_SUCCESS){
wprintf(L"WlanEnumInterfacesfailedwitherror:%u\n",dwResult);
return1;
}else{
wprintf(L"NumEntries:%lu\n",pIfList->dwNumberOfItems);
wprintf(L"CurrentIndex:%lu\n\n",pIfList->dwIndex);
inti;
for(i=;i<(int)pIfList->dwNumberOfItems;i++){
pIfInfo=(WLAN_INTERFACE_INFO*)&pIfList->InterfaceInfo[i];
wprintf(L"InterfaceIndex[%u]:\t%lu\n",i,i);
iRet=StringFromGUID2(pIfInfo->InterfaceGuid,(LPOLESTR)&GuidString,
sizeof(GuidString)/sizeof(*GuidString));
if(iRet==)
wprintf(L"StringFromGUID2failed\n");
else{
wprintf(L"InterfaceGUID[%d]:%S\n",i,GuidString);
}
wprintf(L"InterfaceDescription[%d]:%S",i,
pIfInfo->strInterfaceDescription);
wprintf(L"\n");
wprintf(L"InterfaceState[%d]:\t",i);
switch(pIfInfo->isState){
casewlan_interface_state_not_ready:
wprintf(L"Notready\n");
break;
casewlan_interface_state_connected:
wprintf(L"Connected\n");
break;
casewlan_interface_state_ad_hoc_network_formed:
wprintf(L"Firstnodeinaadhocnetwork\n");
break;
casewlan_interface_state_disconnecting:
wprintf(L"Disconnecting\n");
break;
casewlan_interface_state_disconnected:
wprintf(L"Notconnected\n");
break;
casewlan_interface_state_associating:
wprintf(L"Attemptingtoassociatewithanetwork\n");
break;
casewlan_interface_state_discovering:
wprintf(L"Autoconfigurationisdiscoveringsettingsforthenetwork\n");
break;
casewlan_interface_state_authenticating:
wprintf(L"Inprocessofauthenticating\n");
break;
default:
wprintf(L"Unknownstate%ld\n",pIfInfo->isState);
break;
}
}
}
}
}
intmain()
{
HANDLEhClient=NULL;
DWORDdwMaxClient=;
DWORDdwCurVersion=;
DWORDdwResult=;
PWLAN_INTERFACE_INFO_LISTpIfList=NULL;
//opensaconnectiontotheserver.
dwResult=WlanOpenHandle(dwMaxClient,NULL,&dwCurVersion,&hClient);
if(dwResult!=ERROR_SUCCESS){
wprintf(L"WlanOpenHandlefailedwitherror:%u\n",dwResult);
return1;
}
//enumeratesallofthewirelessLANinterfacescurrentlyenabledonthelocalcomputer.
dwResult=WlanEnumInterfaces(hClient,NULL,&pIfList);
if(dwResult!=ERROR_SUCCESS){
wprintf(L"WlanEnumInterfacesfailedwitherror:%u\n",dwResult);
return1;
}else{
//disconnectsaninterfacefromitscurrentnetwork.
dwResult=WlanDisconnect(hClient,&pIfList->InterfaceInfo[].InterfaceGuid,NULL);//DISCONNECTFIRST
if(dwResult!=ERROR_SUCCESS)
{
printf("WlanDisconnectfailedwitherror:%lu\n",dwResult);
return-;
}
//retrievethelistofavailablenetworksonawirelessLANinterface.
PWLAN_AVAILABLE_NETWORK_LISTpWLAN_AVAILABLE_NETWORK_LIST=NULL;
dwResult=WlanGetAvailableNetworkList(hClient,&pIfList->InterfaceInfo[].InterfaceGuid,
,
NULL,&pWLAN_AVAILABLE_NETWORK_LIST);
if(dwResult!=ERROR_SUCCESS)
{
printf("WlanGetAvailableNetworkListfailedwitherror:%lu\n",dwResult);
WlanFreeMemory(pWLAN_AVAILABLE_NETWORK_LIST);
return-;
}
//connectawlan
LPCWSTRprofileXml;
std::wstringstrHead=
L"<?xmlversion=\"1.0\"encoding=\"US-ASCII\"?>\
<WLANProfilexmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\">\
<name>SampleWPA2PSK</name>\
<SSIDConfig>\
<SSID>\
<name>CJLU</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></keyMaterial>\
</sharedKey>\
</security>\
</MSM>\
</WLANProfile>";
profileXml=strHead.c_str();
WLAN_REASON_CODEWlanreason;
//如果<connectionMode>auto</connectionMode>,为自动连接,则下面的一步可以连接上无线
dwResult=WlanSetProfile(hClient,
&(pIfList->InterfaceInfo[].InterfaceGuid),
,profileXml,NULL,TRUE,NULL,&Wlanreason);
if(ERROR_SUCCESS!=dwResult)
{
printf("wlansetprofilefailed%lu.\r\n",dwResult);
}
//删除无线配置文件
/*
LPCWSTRprofileName;
LPCWSTRnewProfileName;
std::wstringstrprofileName=L"SampleWPA2PSK";
std::wstringstrNewProfileName=L"test";
profileName=strprofileName.c_str();
newProfileName=strNewProfileName.c_str();
dwResult=WlanDeleteProfile(hClient,
&(pIfList->InterfaceInfo[0].InterfaceGuid),
profileName,NULL);
if(ERROR_SUCCESS!=dwResult)
{
printf("wlandeleteprofilefailed%lu.\r\n",dwResult);
}
*/
/*
//重命名无线配置文件,其实只是新建了一个配置文件,并无重命名(更改了wlanapi.h,将此函数换了条件编译位置)
dwResult=WlanRenameProfile(hClient,
&(pIfList->InterfaceInfo[0].InterfaceGuid),
profileName,
newProfileName,
NULL
);
if(ERROR_SUCCESS!=dwResult)
{
printf("wlanRenameprofilefailed%lu.\r\n",dwResult);
}
*/
//网卡关闭和开启(关闭了,就开不了了,除非获取了InterfaceGuid
//然后可以关闭再开启。用fn+F2手动开启)
WLAN_PHY_RADIO_STATEstate;
state.dwPhyIndex=;
state.dot11SoftwareRadioState=dot11_radio_state_on;
PVOIDpData=&state;
dwResult=WlanSetInterface(hClient,&pIfList->InterfaceInfo[].InterfaceGuid,
wlan_intf_opcode_radio_state,sizeof(WLAN_PHY_RADIO_STATE),pData,NULL);
if(dwResult!=ERROR_SUCCESS)
{
wprintf(L"setstatefailed!erris%d\n",dwResult);
}
}
dwResult=WlanCloseHandle(hClient,NULL);
if(dwResult!=ERROR_SUCCESS)
{
wprintf(L"WlanCloseHandlefailed%lu.\r\n",dwResult);
}
listenStatus();
if(pIfList!=NULL){
WlanFreeMemory(pIfList);
pIfList=NULL;
}
return0;
}
C++操作Windows WIFI的更多相关文章
- winreg操作windows注册表详解示例
#coding:utf-8 #=====================================================================#=====本程序演示了WINR ...
- C语言操作WINDOWS系统存储区数字证书相关函数详解及实例
C语言操作WINDOWS系统存储区数字证书相关函数详解及实例 以下代码使用C++实现遍历存储区证书及使用UI选择一个证书 --使用CertOpenSystemStore打开证书存储区. --在循环中 ...
- C# 操作windows服务[启动、停止、卸载、安装]
主要宗旨:不已命令形式操作windows服务 static void Main(string[] args) { var path = @"E:\开发辅助项目\WCF\WCF.Test\WC ...
- 全键盘操作Windows
计算机机用户在使用计算机的时候,是用键盘多一点?还是用鼠标多一点?如果是专业打字员,应该会说他使用键盘多一点,除此之外,多数人都会告诉你,他已经离不开鼠标了,没有鼠标,就不会操作电脑. 如果某一天 ...
- C#通过SC命令和静态公共类来操作Windows服务
调用的Windows服务应用程序网址:http://www.cnblogs.com/pingming/p/5115304.html 一.引用 二.公共静态类:可以单独放到类库里 using Syste ...
- cmd命令行和bat批处理操作windows服务(转载)
一.cmd命令行---进行Windows服务操作 1.安装服务 sc create 服务名 binPath= "C:\Users\Administrator\Desktop\win32srv ...
- (转)Python 操作 Windows 粘贴板
转自: http://outofmemory.cn/code-snippet/3939/Python-operation-Windows-niantie-board Python 操作 Windows ...
- C#使用DirectoryEntry类操作Windows帐户
1.创建windows帐户 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /// <summary> /// 创建Windows帐户 /// </summa ...
- [经验分享]C# 操作Windows系统计划任务
背景:我做了一个事情是要自己提前创建好很多要定时执行的任务,在我不在的时候自动执行这些程序,以保证我的工作能无人值守,那么我就需要建立系统计划任务来帮我完成这件事情,当然用脑子想想如何实现,很简单,每 ...
随机推荐
- python全栈开发-面向对象-初识2
python_17_day 今日主要内容: 1.类空间,对象空间,查询顺序. 2.组合. 1.类空间,对象空间,查询顺序. class Person: animal = '高级动物' soul = ' ...
- 令自己的本地ip可以被外网访问
https://www.ngrok.cc/_book/general/open.html
- TW实习日记:第五天
今天可以说是非常忙的一天了,要再项目中实现微信相关的功能:授权登录以及扫码登录,还有就是自建应用的发送消息.首先功能代码其实在经过了几天的学习之后并没有很难,但是最让我难受的是在项目中去加代码,首先s ...
- HIVE简介及安装
一.简介 百度百科HIVE定义: hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的sql查询功能,可以将sql语句转换为MapReduce任务进行运 ...
- String中intern()方法
intren方法:通俗的讲,是将字符串放入常量池中. new出来的字符串是放在堆中,直接赋值的字符串是放在常量池中的. 对字符串做拼接操作,即做“+”运算,分两种情况 (1)表达式右边是纯字符串常量, ...
- PReLU——Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification
1. 摘要 在 \(ReLU\) 的基础上作者提出了 \(PReLU\),在几乎没有增加额外参数的前提下既可以提升模型的拟合能力,又能减小过拟合风险. 针对 \(ReLU/PReLU\) 的矫正非线性 ...
- Centos 7 zabbix 实战应用
实际需求:公司已经有了100台服务器,现在需要使用zabbix全部监控起来. 先出个方案(规划) 常规监控:cpu,内存,磁盘,网卡 问题:怎样快速添加100台机器 方法1:使用克隆的 ...
- 详讲H5、WebApp项目中常见的坑以及注意事项
首先我们中会有一些常用的meta标签,如下: <!--防止手机中网页放大和缩小--> <meta name="viewport" content="wi ...
- 王者荣耀交流协会final冲刺第五次scrum会议
成员王超,高远博,冉华,王磊,王玉玲,任思佳,袁玥全部到齐,王磊拍照. master:高远博 2.时间跨度 2017年12月5日 18:00 - 18:31,总计31分钟 3.地点 一食堂二楼沙发座椅 ...
- struts通配符*的使用
<action name="user_*" class="com.wangcf.UserAction" method="{1}"> ...