简体   繁体   English

如何使用Windows Native Wifi功能连接到请求网络安全密钥的Wifi?

[英]How to connect to a Wifi that requests for a network security key using Windows Native Wifi Functions?

I'm developing a way to connect to a Wifi using VS2010 and currently stuck on how to make it connect with a network security key. 我正在开发一种使用VS2010连接到Wifi的方法,目前仍在研究如何使其与网络安全密钥连接。 I am able to enumerate all the Wifi hotspot in my area and get their SSID, MAC addresses, etc using Windows Native Wifi Functions (WlanOpenHandle, WlanEnumInterfaces, WlanQueryInterface, WlanGetNetworkBssList). 我能够枚举我所在区域的所有Wifi热点,并使用Windows本机Wifi函数(WlanOpenHandle,WlanEnumInterfaces,WlanQueryInterface,WlanGetNetworkBssList)获取其SSID,MAC地址等。 I've already read about WlanConnect() on MSDN but I'm still clueless. 我已经在MSDN上阅读了有关WlanConnect() ,但我仍然一无所知。 Can you give me some hints that would make the code connect to a Wifi that asks for a network security key? 您能否给我一些提示,以使代码连接到要求网络安全密钥的Wifi?

Assuming you have at least one saved Wifi connection run the command 假设您至少有一个已保存的Wifi连接,请运行以下命令

netsh wlan export profile

This will export all your Wifi profiles as XML files in the current directory. 这会将所有Wifi配置文件导出为当前目录中的XML文件。

When you call WlanConnect you can supply a literal XML profile string in the WLAN_CONNECTION_PARAMETERS structure if wLanConnectionMode is set to wlan_connection_mode_temporary_profile . 如果将wLanConnectionMode设置为wlan_connection_mode_temporary_profile则在调用WlanConnect时可以在WLAN_CONNECTION_PARAMETERS结构中提供文字XML配置文件字符串。

If you can use the XML from one of your exported profiles to connect successfully to a secured network, then presumably you should be able to alter the XML and use the same technique to connect to new networks. 如果可以使用导出的配置文件之一中的XML成功连接到安全网络,则大概应该可以更改XML并使用相同的技术连接到新网络。

I've never tried this, and I've no idea what encoding is used for the key stored in the XML, but it seems like a possible way of solving your problem. 我从未尝试过这种方法,也不知道XML中存储的密钥使用了哪种编码,但是这似乎是解决问题的一种可行方法。

You will need an example profile to start with, as arx had suggested. 正如arx所建议的,您将需要一个示例配置文件开始。 When exporting a profile, add the key=clear arg. 导出配置文件时,添加key = clear arg。 This will export the profile with the key in it. 这将导出配置文件,其中包含密钥。 You can than see the setup that you would need to adjust. 然后,您可以看到需要调整的设置。

Example : netsh wlan export profile name=”<profileName>” folder=”<SaveLocation>” key=clear 示例: netsh wlan export profile name=”<profileName>” folder=”<SaveLocation>” key=clear

The resulting xml will contain a section with: 生成的xml将包含以下部分:

<MSM>
    <security>
        <authEncryption>
            <authentication>WPA2PSK</authentication>
            <encryption>AES</encryption>
            <useOneX>false</useOneX>
        </authEncryption>
        <sharedKey>
            <keyType>passPhrase</keyType>
            <protected>false</protected>
            <keyMaterial>YourPaswordTextHERE</keyMaterial>
        </sharedKey>
    </security>
</MSM>

So once you have your profile string, update the keyMaterial element with your programmatically obtained password. 因此,有了配置文件字符串后,请使用以编程方式获取的密码来更新keyMaterial元素。 Once this is done you should be able to call wlanConnect. 完成此操作后,您应该可以致电wlanConnect。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM