DEV Community

Cover image for Get Network Passwords
Muhammad Usman
Muhammad Usman

Posted on

Get Network Passwords

Welcome to this blog post where I will walk you through the process of retrieving the Wi-Fi password saved on your PC. But before we proceed, we would like to issue a warning for educational purposes only. I do not condone or promote the unauthorized access of any Wi-Fi network without the owner's consent. The method we are going to discuss should only be used for educational purposes, to help you understand how Wi-Fi passwords are stored on your PC and to enable you to better protect your network from potential security breaches.

With that said, let's dive into the process of retrieving the Wi-Fi password saved on your PC. Many of us have experienced a situation where we want to connect a new device to our Wi-Fi network, but we can't remember the password. Fortunately, your PC stores the Wi-Fi password for each network that you have connected to in the past, and it's relatively easy to retrieve it.

Linux

#!/bin/bash

meta_data=$(netsh wlan show profiles)
data=$(echo "$meta_data" | iconv -f "windows-1251" -t "utf-8" | sed -n "s/    All User Profile     : //p")
profiles=($data)

printf "%-30s| %-s\n" "Wi-Fi Name" "Password"
printf "______________________________________________\n"

for i in "${profiles[@]}"
do
    results=$(netsh wlan show profile "$i" key=clear)
    password=$(echo "$results" | sed -n "s/    Key Content            : //p")

    if [ -z "$password" ]
    then
        password=""
    fi

    printf "%-30s| %-s\n" "$i" "$password"
done
Enter fullscreen mode Exit fullscreen mode

Save this file with a suitable name, such as "wifi-passwords.sh". Make sure you set the executable bit for the file by running the following command:

chmod +x wifi-passwords.sh
Enter fullscreen mode Exit fullscreen mode

You can then run the script using:

./wifi-passwords.sh
Enter fullscreen mode Exit fullscreen mode

This will display a list of all saved Wi-Fi networks and their passwords. Note that this script may not work on all systems or may require modifications to work properly.

Windows

To convert the shell script to a batch file, you can create a new file with a .bat extension and add the following code:

@echo off
setlocal enabledelayedexpansion

for /f "tokens=2 delims=: " %%a in ('netsh wlan show profiles ^| findstr "All User Profile"') do (
    set "profile=%%a"
    set "profile=!profile:~1,-1!"
    set "password="
    for /f "tokens=2 delims=: " %%b in ('netsh wlan show profile "!profile!" key^=clear ^| findstr "Key Content"') do (
        set "password=%%b"
        set "password=!password:~1!"
        echo !profile! | powershell -Command "$input | Out-Host"
        echo !password! | powershell -Command "$input | Out-Host"
        echo "______________________________________________"
    )
)
Enter fullscreen mode Exit fullscreen mode

Save this file with a suitable name, such as "wifi-passwords.bat". You can then run the batch file by double-clicking on it. This will display a list of all saved Wi-Fi networks and their passwords.

Note that the batch file may not work on all systems or may require modifications to work properly. Also, the batch file may display some non-ASCII characters incorrectly due to differences in character encoding between Bash and Windows Command Prompt

Top comments (0)