如何仅使用CMD连接到WiFi? [英] How to connect to a WiFi using CMD only?
问题描述
如何通过使用CMD输入密码来连接到新的WiFi?
How to connect to a new WiFi by enter a password using CMD?
对于我的学校项目,我决定使用cmd编写一个WiFi_manager程序.
For my school project I have decided to make a WiFi_manager program using cmd.
我知道要显示所有WiFi网络(以cmd为单位):
I know to display all WiFi networks (in cmd):
netsh wlan show networks
现在可以说我想连接到以前从未连接过的WiFi网络.而且该WiFi尚未添加到配置文件中.
Now lets say I want to connect to a WiFi network that I never connected before. And that WiFi is not yet added to profiles.
但是我知道WiFi的密码.
But I know the password of the WiFi.
1)命令行是什么.
获取以下WiFi网络信息:
Given the information of WiFi network below:
SSID 3 : Ismail
Network type : Infrastructure
Authentication : WPA-Personal
Encryption : CCMP
and password is "Thanks_bro".
如果这不可能,可以使用C ++完成吗?
If this is not possible, can it be done using C++?
推荐答案
所以您已经知道netsh wlan
如果输入它,则会获得可能命令的列表.一个是add
.
If you enter it you get a list of possible commands. One is add
.
如果输入netsh wlan add
,则会得到另一个可能的子命令列表.一个是profile
.
If you enter netsh wlan add
you get another list of possible subcommands. One is profile
.
如果输入netsh wlan add profile
,则会获得有关其所有可能参数的详细说明.一个需要的参数是一个包含配置文件信息的XML文件.
If you enter netsh wlan add profile
you get a detailed explanation about all its possible parameters. One needed parameter is a XML file containing the profile informations.
那么如何获得这样的XML文件呢?返回netsh wlan
并研究关键字.有export
.
So how to get such an XML file? Go back to netsh wlan
and study the keywords. There is export
.
如果输入netsh wlan export
,则会得到另一个可能的子命令列表.一个是profile
.它将在您的本地目录中创建一个XML,其中包含当前WiFi连接所需的信息.
If you enter netsh wlan export
you get another list of possible subcommands. One is profile
. It creates an XML in your local directory containing the needed informations for your current WiFi connection.
如果您想以明文形式获取密码,则还必须添加参数key=clear
.使整个命令变为
If you like to get the password in clear text, you'll also have to add the parameter key=clear
. Make the whole command becoming
netsh wlan export profile key=clear
这里是一个示例,其中已经包含所需的占位符
Here is an example which already contains the needed placeholders
<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>{SSID}</name>
<SSIDConfig>
<SSID>
<name>{SSID}</name>
</SSID>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>WPA2PSK</authentication>
<encryption>AES</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>false</protected>
<keyMaterial>{password}</keyMaterial>
</sharedKey>
</security>
</MSM>
<MacRandomization xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
<enableRandomization>false</enableRandomization>
</MacRandomization>
</WLANProfile>
只需将关键字{SSID}
(出现两次)和{password}
替换为所需的值,然后通过调用导入该文件
Simply replace the keywords {SSID}
(occurs two times) and {password}
with the desired values and import that file by calling
netsh wlan add profile filename="myProfile.xml"
这篇关于如何仅使用CMD连接到WiFi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!