简体   繁体   中英

Is there a variable for the connected wlan?

I started writing this small batch file, where I get all the wlan data with:

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. As there is also a line containing B SSID we ignore it with eol=B .
    • Now, we want to parse the value after : symbol, so we set it as delimeter. We can access the network name, now, setting tokens to 2 .
      • We remove all unneded spaces in the result with another for loop specifying tokens option to * .
        • So, now, we want all the info about currently connected network ( %%A ). We redirect output to wlan.txt .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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