Parse output of NETSH

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
_Danny___
Posts: 2
Joined: 11 Feb 2017 21:56

Parse output of NETSH

#1 Post by _Danny___ » 11 Feb 2017 22:11

Hi

I want to do the following in a batch file.

Code: Select all

netsh wlan show profiles


Will return names of WiFi networks in range, say might be a list of 5 or six etc

For each of the list of 5 or 6 networks:

Code: Select all

netsh wlan show profiles {WiFi Network Name} key=clear


Then output the list to my profile name in windows under desk top something like

Code: Select all

Echo     Wi-Fi Network Password%Key%>>%userprofile%\desktop\%username%.txt


Or something similar so the output text file looks like (example)

Network Profile Name1 PSW = Value of Key Content1
Network Profile Name2 PSW = Value of Key Content2
Network Profile Name3 PSW = Value of Key Content3
etc...

I think the loop will look something like:

Code: Select all

For /F "Tokens=5" %%K In ('Netsh Wlan Show Profile') Do For /F "tokens=2,*" %%L In ('Netsh Wlan Show Profile Name^="%%K" Key^=Clear^|Find /I "Content"'


I dont know just guessing about the loop command. Any super programmers out there that can help me?

Danny

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Parse output of NETSH

#2 Post by aGerman » 12 Feb 2017 05:19

The output of NETSH is highly language-dependend. Out of your example I guess this should work for you

Code: Select all

@echo off &setlocal
for /f "tokens=2 delims=:" %%i in ('netsh wlan show profiles') do for /f "tokens=*" %%j in ("%%i") do (
  for /f "tokens=2 delims=:" %%k in ('netsh wlan show profiles name^="%%j" key^=clear^|find /i "Content"') do for /f "tokens=*" %%l in ("%%k") do (
    echo %%j PSW=%%l
  )
)
pause

... where at least the search term "Content" will be different for other languages.

Steffen

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Parse output of NETSH

#3 Post by Compo » 12 Feb 2017 05:59

Without seeing the actual output, there's not a lot we can offer in parsing it to produce the output you specifically need.

If you run the following and edit the output.log to protect the sensitive information before posting it we may have a better chance:

Code: Select all

@Echo Off
(   For /f "Tokens=1* Delims=:" %%A In ('netsh wlan show profiles'
   ) Do If Not "%%B"=="" For /F "Tokens=*" %%C In ("%%B"
   ) Do netsh wlan show profile name="%%C" key=clear
)>"%UserProfile%\Desktop\output.log"
notepad.exe "%UserProfile%\Desktop\output.log"

_Danny___
Posts: 2
Joined: 11 Feb 2017 21:56

Re: Parse output of NETSH

#4 Post by _Danny___ » 13 Feb 2017 12:25

agerman and compo - Thanks you guys! You are AWSOME!

Danny

Post Reply