简体   繁体   English

连接的WLAN是否有变量?

[英]Is there a variable for the connected wlan?

I started writing this small batch file, where I get all the wlan data with: 我开始写这个小批处理文件,在其中获取所有wlan数据:

netsh wlan show profile (name) key=clear

This is not a problem but I am asking if there is a variable like for example: 这不是问题,但是我问是否有一个变量,例如:

%CurrentWlan%

so I can do: 所以我可以做:

netsh wlan show profile %CurrentWlan% key=clear >wlan.txt 

Here is a possible solution: 这是一个可能的解决方案:

@echo off

for /f "eol=B tokens=*" %%A IN ('netsh wlan show interfaces ^| findstr SSID') do (
    for /f "delims=: tokens=2" %%A IN ("%%A") do (
        for /f "tokens=*" %%A IN ("%%A") do (
            netsh wlan show profiles "%%A" key=clear >wlan.txt
        )
    )
)

Which I am going to break it down: 我要分解的是:

  • We first parse the output of the command netsh wlan show interfaces searching for SSID string. 我们首先解析命令netsh wlan show interfaces的输出,以搜索SSID字符串。 As there is also a line containing B SSID we ignore it with eol=B . 由于还有一行包含B SSID的行,因此我们用eol=B忽略它。
    • Now, we want to parse the value after : symbol, so we set it as delimeter. 现在,我们想 :符号解析值,因此我们将其设置为delimeter。 We can access the network name, now, setting tokens to 2 . 现在,我们可以访问网络名称,将tokens设置为2
      • We remove all unneded spaces in the result with another for loop specifying tokens option to * . 我们使用另一个for循环,将结果中所有不需要的空格删除,将* tokens指定为tokens选项。
        • So, now, we want all the info about currently connected network ( %%A ). 因此,现在,我们需要有关当前连接的网络( %%A )的所有信息。 We redirect output to wlan.txt . 我们将输出重定向到wlan.txt

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

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