Find Wifi Password using Python - Aman Aadi

Find Wifi Password using Python

Introduction:

Have you ever forgotten the password for a Wi-Fi network your device was previously connected to? Fear not! In this blog post, we will explore an exciting Python project that allows you to retrieve previously connected Wi-Fi passwords stored on your computer. With just a few lines of Python code, you can unveil the hidden secrets of Wi-Fi passwords and regain access to your favorite networks. This project showcases the power and versatility of Python, providing a practical and fun solution to a common problem faced by many users.

Understanding the Wi-Fi Password Retrieval Project:

We’ll use a simple Python script to access the Wi-Fi passwords stored on your computer. Please note that this script will only work on Windows operating systems.

How would the python code work? It will run a system command “netsh wlan show profiles” to find all previous connected wi-fi names and “netsh wlan show profiles name=”<wifi_name>” key=clear” to find the password. And we will just filter filter the wi-fi names and passwords of previous connections.

Requirements:

Before we begin, ensure you have Python installed on your computer. You can download the latest version from the official Python website (https://www.python.org/downloads/) and follow the installation instructions. Additionally, a code editor, such as Visual Studio Code or PyCharm, will make coding and testing more convenient.

In Python, we’ll use the subprocess module to interact with the command prompt (Windows) or terminal (macOS and Linux) and re or RegEX module to find specific pattern in a string. The script will execute commands to access the stored Wi-Fi profiles and retrieve the passwords.

Python Code:

# importing modules
import subprocess
import re

# capturing the wi-fi names
profiles = 'netsh wlan show profile'
networks = subprocess.check_output(profiles, shell=True).decode()
network_names = re.findall("(?:Profile\s*:\s)(.*)", networks)   #profiles followed by any number of blank space followed by collon and a blank space. After that all character

# printing the description
print("\n--- There are the previous connected wi-fi and there passwords ---\n")

# capturing the password by the wifi names. Also showing the wifi names with password
for network_name in network_names:
    keys = f'netsh wlan show profile "{network_name}" key=clear'
    passwords = subprocess.check_output(keys, shell=True).decode()
    password = re.findall("(?:Key Content\s*:\s)(.*)", passwords)
    print(f"{network_name.strip()} : {''.join(password)}")

# printing the new line
print("\n")

Output:

Find Wifi Password using Python - Aman Aadi

Conclusion:

Congratulations! You’ve successfully created a Python script to find previously connected Wi-Fi passwords. With this powerful tool, you can access Wi-Fi networks that you may have forgotten the passwords for, simplifying your digital life. Please note that this script retrieves passwords only for previously connected networks and requires administrative privileges on some systems. As a responsible user, ensure that you have appropriate authorization to access this information. Python, with its versatility and ease of use, continues to empower us to solve real-world challenges like Wi-Fi password retrieval. Happy coding, and may your Wi-Fi connections always remain secure and accessible!

Discover more from Aman Aadi

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top