WiFiPasswordReveal

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
elias
Posts: 5
Joined: 19 May 2016 18:20

WiFiPasswordReveal

#1 Post by elias » 19 May 2016 18:30

A simple and handy script to reveal all the saved Wifi passwords.

The script can also be retrieved from GitHub https://github.com/PassingTheKnowledge/Batchography/blob/master/WifiPasswordReveal.bat:

Code: Select all

@echo off

setlocal enabledelayedexpansion

:main
    title WiFiPasswordReveal v1.0
   
    echo.
    echo Reveal all saved WiFi passwords Batch file script v1.0
    echo.

    :: Get all the profiles
    call :get-profiles r

    :: For each profile, try to get the password
    :main-next-profile
        for /f "tokens=1* delims=," %%a in ("%r%") do (
            call :get-profile-key "%%a" key
            if "!key!" NEQ "" (
                echo WiFi: [%%a] Password: [!key!]
            )
            set r=%%b
        )
        if "%r%" NEQ "" goto main-next-profile

    echo.
    pause

    goto :eof

::
:: Get the WiFi key of a given profile
:get-profile-key <1=profile-name> <2=out-profile-key>
    setlocal

    set result=

    FOR /F "usebackq tokens=2 delims=:" %%a in (
        `netsh wlan show profile name^="%~1" key^=clear ^| findstr /C:"Key Content"`) DO (
        set result=%%a
        set result=!result:~1!
    )
    (
        endlocal
        set %2=%result%
    )

    goto :eof

::
:: Get all network profiles (comma separated) into the result result-variable
:get-profiles <1=result-variable>
    setlocal

    set result=

   
    FOR /F "usebackq tokens=2 delims=:" %%a in (
        `netsh wlan show profiles ^| findstr /C:"All User Profile"`) DO (
        set val=%%a
        set val=!val:~1!

        set result=%!val!,!result!
    )
    (
        endlocal
        set %1=%result:~0,-1%
    )

    goto :eof


Hackoo
Posts: 86
Joined: 15 Apr 2014 17:59

Re: WiFiPasswordReveal

#2 Post by Hackoo » 03 Jul 2016 22:59

Hi ! just i want to say that this script dosen't works on french machines like me :roll:
But never mind i will invite you and all the membres here to test this batch script and tell if it works or not on your machines
You can find this script here in this link

batchcc
Posts: 139
Joined: 17 Aug 2015 06:05
Contact:

Re: WiFiPasswordReveal

#3 Post by batchcc » 04 Jul 2016 09:01

I have tried this script on windows vista and windows 7 (English) and it doesn't work for me either.

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

Re: WiFiPasswordReveal

#4 Post by aGerman » 04 Jul 2016 09:58

Neither of them works for me (Win10, German). Here is the output if I run the commands manually

Code: Select all

C:\>netsh wlan show profiles

Profile auf Schnittstelle WiFi:

Gruppenrichtlinienprofile (schreibgeschützt)
---------------------------------
    <Kein>

Benutzerprofile
---------------
    Profil für alle Benutzer : FRITZ!Box Fon WLAN 7390


C:\>netsh wlan show profile name="FRITZ!Box Fon WLAN 7390" key=clear

Das Profil "FRITZ!Box Fon WLAN 7390" auf Schnittstelle WiFi:
=======================================================================

Angewendet: Profil für alle Benutzer

Profilinformationen
-------------------
    Version                : 1
    Typ                    : Drahtlos-LAN
    Name                   : FRITZ!Box Fon WLAN 7390
    Steuerungsoptionen     :
        Verbindungsmodus   : Automatisch verbinden
        Netzwerkübertragung  : Verbinden, nur wenn dieses Netzwerk überträgt
        Automatisch wechseln         : Nicht zu anderen Netzwerken wechseln.
        MAC-Randomisierung  : Deaktiviert

Konnektivitätseinstellungen
---------------------
    Anzahl von SSIDs        : 1
    SSID-Name              : "FRITZ!Box Fon WLAN 7390"
    Netzwerktyp            : Infrastruktur
    Funktyp                : [ Beliebiger Funktyp ]
    Herstellererweiterung          : Nicht vorhanden

Sicherheitseinstellungen
------------------------
    Authentifizierung         : WPA2-Personal
    Verschlüsselung                 : CCMP
    Sicherheitsschlüssel   : Vorhanden
    Schlüsselinhalt            : 9612757721470620

Kosteneinstellungen
-------------------
    Kosten                 : Uneingeschränkt
    Überlastet              : Nein
    Datenlimit bald erreicht: Nein
    Über Datenlimit         : Nein
    Roaming                : Nein
    Kostenquelle            : Standard


C:\>

I fear trying to get a solution that works language independent may become a waste of time :?

Regards
aGerman

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: WiFiPasswordReveal

#5 Post by foxidrive » 04 Jul 2016 20:31

I was interested to read this aGerman and tried the netsh command and got this error:

Code: Select all

c:\>netsh wlan show profiles
The Wireless AutoConfig Service (wlansvc) is not running.

Then my brain realised that I don't use wireless on this computer... so I added a USB wireless adapter and tried it again LOL


This may work in other languages and it's not particularly clever code, but it uses Aacini's findrepl to isolate the 11th line from the end and which seems to be the wireless password location.

Code: Select all

@echo off
for /f "tokens=2 delims=:" %%a in ('netsh wlan show profiles ^|find " : "') do for /f "tokens=*" %%b in ("%%a") do (
for /f "tokens=2 delims=:" %%c in (
  'netsh wlan show profiles name^="%%b" key^=clear ^|findrepl /o:-11:-11') do for /f "tokens=*" %%d in ("%%c") do (
     echo User              : "%%b"
     echo Wireless Password : "%%d"
))
pause & goto :EOF


It works in English Windows 8.1 in my limited test.


I fiddled a little more and used vanilla batch code to do the same thing.

Code: Select all

@echo off
set cmd1=netsh wlan show profiles ^^^|find " : "
set cmd2=netsh wlan show profiles name^^^="%%b" key^^^=clear ^^^| find /n /v ""

for /f "tokens=2 delims=:" %%a in ('%cmd1%') do for /f "tokens=*" %%b in ("%%a") do (
   for /f "delims=[]" %%z in ('%cmd2%') do set /a pwdline=%%z - 10
      for /f "tokens=2 delims=:" %%c in ('%cmd2% ^| call find "[%%pwdline%%]" ') do (
         for /f "tokens=*" %%d in ("%%c") do (
            echo User              : "%%b"
            echo Wireless Password : "%%d"
)))
pause & goto :EOF

Post Reply