cornbeetle

Display Wireless SSIDs and Security Keys

Dec 14th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.82 KB | None | 0 0
  1. :: Credit to ItsGotToMakeSense, from a Reddit post: https://www.reddit.com/r/usefulscripts/comments/5ec5ha/batch_a_script_to_view_the_wireless_ssids_and/
  2. :: This is an enhanced version, adding multiple color functionality.
  3.  
  4. @echo off
  5. setlocal EnableDelayedExpansion
  6.  
  7. :START
  8. color 07
  9. call :initColor
  10. cls
  11.  
  12. title View wireless SSID list
  13.  
  14. ::Display list of SSIDs stored in this computer and prompt user to choose one
  15. Netsh wlan show profiles
  16. Echo If you wish to view the security key for one of the above SSIDs,
  17. Set /p SSID=enter its name here:
  18. echo.
  19.  
  20. ::Detect whether the user's chosen SSID is in the list
  21. Netsh wlan show profiles | find /i "%SSID%" > NUL || call :applyColor 47 "   Sorry, that SSID is not found.   " nossid
  22.  
  23. :VIEWKEY
  24. ::The below spacing is deliberately wide for readability of results when a security key is displayed
  25. call :applyColor 27 "    SSID                   : %SSID%    "
  26.  
  27. ::Display key content if available
  28. netsh wlan show profile name="%SSID%" key=clear | find "Key Content" || call :applyColor 47 "  The security key is not found for this SSID.  " nokey
  29. echo.
  30. pause
  31. echo.
  32.  
  33. ::Give the user a chance to view another key
  34. choice /c YN /m "Do you want to view another?"
  35. If errorlevel 2 goto EXIT
  36. If errorlevel 1 goto start
  37.  
  38. :EXIT
  39. exit /b
  40.  
  41. :: Credit to Jeb for color conversion routine. See URL http://stackoverflow.com/questions/4339649/how-to-have-multiple-colors-in-a-windows-batch-file
  42. :initColor
  43. for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  44.   set "DEL=%%a"
  45. )
  46. <nul > X set /p ".=."
  47. exit /b
  48.  
  49. :applyColor
  50. set "param=^%~2" !
  51. set "param=!param:"=\"!"
  52. findstr /p /A:%1 "." "!param!\..\X" nul
  53. <nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
  54. del X
  55. echo.
  56. if "%3"=="nossid" pause & goto:start
  57. if "%3"=="nokey" pause & goto:start
  58. exit /b
Add Comment
Please, Sign In to add comment