DosTips.com

A Forum all about DOS Batch
It is currently 22 Jul 2017 18:48

All times are UTC-06:00




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Parse output of NETSH
PostPosted: 11 Feb 2017 22:11 
Offline

Joined: 11 Feb 2017 21:56
Posts: 2
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


Top
   
PostPosted: 12 Feb 2017 05:19 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 2714
Location: Germany
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


Top
   
PostPosted: 12 Feb 2017 05:59 
Offline

Joined: 21 Mar 2014 08:50
Posts: 418
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"


Top
   
PostPosted: 13 Feb 2017 12:25 
Offline

Joined: 11 Feb 2017 21:56
Posts: 2
agerman and compo - Thanks you guys! You are AWSOME!

Danny


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Limited