@echo off
chcp 65001 >nul
cls
title Network Tool
color a

:MENU
cls
echo.	███╗   ██╗███████╗████████╗██╗    ██╗ ██████╗ ██████╗ ██╗  ██╗    ████████╗ ██████╗  ██████╗ ██╗     
echo.	████╗  ██║██╔════╝╚══██╔══╝██║    ██║██╔═══██╗██╔══██╗██║ ██╔╝    ╚══██╔══╝██╔═══██╗██╔═══██╗██║     
echo.	██╔██╗ ██║█████╗     ██║   ██║ █╗ ██║██║   ██║██████╔╝█████╔╝        ██║   ██║   ██║██║   ██║██║     
echo.	██║╚██╗██║██╔══╝     ██║   ██║███╗██║██║   ██║██╔══██╗██╔═██╗        ██║   ██║   ██║██║   ██║██║     
echo.	██║ ╚████║███████╗   ██║   ╚███╔███╔╝╚██████╔╝██║  ██║██║  ██╗       ██║   ╚██████╔╝╚██████╔╝███████╗
echo.	╚═╝  ╚═══╝╚══════╝   ╚═╝    ╚══╝╚══╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝       ╚═╝    ╚═════╝  ╚═════╝ ╚══════╝
echo.
echo Listing all connected networks:
echo.
echo.════════════════════════════════════════════
netsh wlan show profiles | findstr "All User Profile"
echo.════════════════════════════════════════════						
echo.							
set /p wifiname=Enter WiFi Name (SSID) or "all": 

if /i "%wifiname%"=="all" (
    cls
    echo Retrieving wifi passwords from all connected SSID's:
    timeout /t 1 >nul
    set outputFile=wifi_passwords.txt
    echo Wi-Fi Networks and Passwords > "%outputFile%"
    echo ------------------------------------------ >> "%outputFile%"
    for /f "tokens=*" %%i in ('netsh wlan show profiles ^| findstr "All User Profile"') do (
        for /f "tokens=2 delims=:" %%j in ('echo %%i') do (
            set "profile=%%j"
            setlocal enabledelayedexpansion
            set "profile=!profile:~1!"
            endlocal
            call :showPassword "!profile!"
        )
    )
    echo All passwords have been saved in "%outputFile%" and copied to clipboard.
    type "%outputFile%" | clip
    pause
    goto MENU
) else (
    cls
    echo Retrieving password for "%wifiname%":
    timeout /t 1 >nul
    netsh wlan show profiles name="%wifiname%" key=clear | findstr "Key Content" > temp.txt
    type temp.txt | clip
    echo Password copied to clipboard and saved in "temp.txt"
    timeout /t 1 >nul
    cls
    echo Password retrieved:
    netsh wlan show profiles name="%wifiname%" key=clear | findstr "Key Content"
    del temp.txt
    pause
    goto MENU
)

:showPassword
setlocal enabledelayedexpansion
set "profileName=%1"
echo Network: !profileName! >> "%outputFile%"
for /f "tokens=*" %%k in ('netsh wlan show profile name^="!profileName!" key^=clear ^| findstr "Key Content"') do (
    for /f "tokens=2 delims=:" %%l in ('echo %%k') do (
        set "password=%%l"
        setlocal enabledelayedexpansion
        set "password=!password:~1!"
        echo Password: !password! >> "%outputFile%"
        echo Network: !profileName!, Password: !password!
        endlocal
    )
)
endlocal
goto :eof

