Page 1 of 1

Parse output of NETSH

Posted: 11 Feb 2017 22:11
by _Danny___
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

Re: Parse output of NETSH

Posted: 12 Feb 2017 05:19
by aGerman
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

Re: Parse output of NETSH

Posted: 12 Feb 2017 05:59
by Compo
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"

Re: Parse output of NETSH

Posted: 13 Feb 2017 12:25
by _Danny___
agerman and compo - Thanks you guys! You are AWSOME!

Danny