header logo

Blogs - olinone.in

Read The Blogs from olinone.in

Easily retrieve windows Wi Fi passwords using the script

05 December, 2020 - By Bhanu

Wi-Fi Password Retrieval Script
To get started, open your favorite text editor, create a new file, and paste in the entire script shown below.

#!/bin/sh

# -----------  SET COLORS  -----------
COLOR_RED=$'\e[31m'
COLOR_CYAN=$'\e[36m'
COLOR_YELLOW=$'\e[93m'
COLOR_GREEN=$'\e[32m'
COLOR_RESET=$'\e[0m'

#
# Helper Function to get stored Wi-Fi network SSIDs
# --------------------------------------------------------------------------
getwifinetworks() {
    echo "#    "
    echo "#    Saved Network SSIDs"
    echo "#    -------------------"
    netsh wlan show profiles | findstr All | sed "s/    All User Profile     : /${COLOR_RESET}#    ${COLOR_CYAN}/"
    echo "${COLOR_RESET}#    -------------------"
    echo "#    "
}

#
# Get password of stored Wi-Fi network by SSID.
# --------------------------------------------------------------------------
# Display list of stored SSIDs
getwifinetworks

# Prompt user for Wi-Fi SSID
echo "#    Enter the network name (SSID)"
echo "#    from the list above: "
echo "#    "
read -e -p "#    SSID: ${COLOR_CYAN}" SSID
eval SSID=$SSID

# If SSID is empty, exit early
if [ -z "$SSID" ]; then
    echo "${COLOR_RESET}#    "
    echo "#    ${COLOR_RED}An SSID is required. Please try again.${COLOR_RESET}"
else
    pass=$(netsh wlan show profile name="$SSID" key=clear | findstr Key)

    # If password is empty, notify user they may need
    # elevated privileges
    if [ -z "$pass" ]; then
        echo "${COLOR_RESET}#    "
        echo "#    ${COLOR_RED}If the network SSID appeared in the list above,${COLOR_RESET}"
        echo "#    ${COLOR_RED}fetching the password may require elevated privileges.${COLOR_RESET}"
        echo "#    "
        echo "#    ${COLOR_YELLOW}Open a new prompt with administrator rights${COLOR_RESET}"
        echo "#    ${COLOR_YELLOW}and try running the 'getwifipassword' command again.${COLOR_RESET}"
        echo "#    ${COLOR_YELLOW}Otherwise, the password is not stored on this device.${COLOR_RESET}"
    else
        echo "${COLOR_RESET}#    "
        echo "#    Password for '${SSID}':"
        echo "#    -----------------------------"
        echo "#   " $pass | sed "s/Key Content : /${COLOR_GREEN}/"
        echo "${COLOR_RESET}#    -----------------------------"
    fi
fi

Save the file as getwifipassword.sh. You will want to save the script in a location that you can easily access from the command line. Alternatively, you can save the file at the location of your choosing and create an alias.

TIP

If you're lazy, you can download the script directly from GitHub (opens new window).

#Usage
To launch the interactive prompt, simply open Command Prompt (or Git Bash, or whatever your terminal of choice happens to be) and call the script (or use the alias).

# Command Prompt
C:\Users\MartyMcfly>bash /path/to/getwifipassword.sh

# ====
#  OR
# ====

# Git Bash
$ bash /path/to/getwifipassword.sh

When the prompt loads, you will be shown a list of saved network SSIDs.

NOTE

The SSID list may not include all of saved networks depending on the security settings on your computer.

Enter the SSID you would like to retrive the password for by typing the SSID name exactly as it appears in the list, then press Enter.

#
#    Saved Network SSIDs
#    -------------------
#    CompanyGuestPortal
#    THEROUTER
#    Home_Network
#    -------------------
#
#    Enter the network name (SSID)
#    from the list above:
#
#    SSID:
The prompt will output the stored network password, if it exists.

NOTE

Some Wi-Fi passwords will require elevated privileges to access. Open a new prompt with administrator rights and try running the command again.

#Create a Bash Alias
If you use Bash, you may set up an alias to call the script from anywhere instead of having to navigate to the directory where you saved the script.

To create the alias, open your .bashrc file (or create one if it does not already exist with touch ~/.bashrc). Copy and paste in the function below. Then, to call the script from anywhere, simply enter getwifipassword on your command line.

# .bashrc

# ... previous lines ...

function getwifipassword() {
  /path/to/getwifipassword.sh;
}
alias getwifipassword=getwifipassword

Write Your Comments

Please write here your valuable comments or review:

Comments

    mobile application of the olinone.in

    OLINONE IN MOBILE APP DOWNLOAD NOW

    Looking for the Best Service Provider? Get the App!

    • Find nearby listings
    • Easy service enquiry
    • Listing reviews and ratings
    • Manage your listing, enquiry and reviews
    We'll send you a link, open it on your phone to download the app
    android app of the olinone.in

    copyrights © 2020 olinone.in.   All rights reserved.