How to use Python script to quickly check the password of the connected WiFi network?

Forgetting the WiFi password is a problem we often encounter in our daily life, especially when we need to reconnect to the WiFi network after changing the device or reinstalling the system, if we forget the password, we cannot connect to the network. To solve this problem, some programmers have developed Python scripts that can help us to view the passwords of connected WiFi networks.

In this article, we will introduce how to quickly view the passwords of connected WiFi networks using a Python script. We'll take a sample script as an example and walk through how to use it to view WiFi passwords.

sample script

First, let's look at the code of the sample script:

```
import subprocess
import re

# Project name: wifi password extraction
# Author: TechLens
# Get wifi list
output = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('gbk')
wifis = re. findall(r'All user profiles: (.*)\r', output)

# Check the password corresponding to each wifi
for wifi in wifis:
    output = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', wifi, 'key=clear']).decode('gbk ',
                                                                                                     errors='ignore')
    password = re.findall(r'key content: (.*)\r', output)
    print(f'wifi name: {wifi}, password: {password[0] if password else "Unable to fetch"}')

input('Press enter to confirm and exit')
```

This script uses Python's subprocess module and re module to obtain the password of the connected WiFi network by calling the operating system's command line tools. The specific implementation process of the script is as follows:

1. Use the subprocess module to call the command-line tool netsh wlan show profiles to obtain a list of connected WiFi networks.
2. Use the re module to extract the name of the WiFi network from the output.
3. Use the subprocess module to call the command-line tool netsh wlan show profile <wifi_name> key=clear to obtain the password of the specified WiFi network.
4. Use the re module to extract the password of the WiFi network from the output.
5. Enter the name and password of the WiFi network.

View WiFi passwords using a sample script

Next, let's demonstrate how to use a sample script to view WiFi passwords.

1. Open the command line tool

First, we need to open the command line tool. In the Windows system, you can press the Win+R key, then enter cmd, and press the Enter key to open the command line tool.

2. Run the sample script

On the command line, switch to the directory where the sample script is located, then type python wifi_password.py, and press Enter to run the script.

3. View WiFi password

After the script runs, it will output the name and password of the connected WiFi network. If the password cannot be extracted, "Unable to extract" will be displayed.

4. Exit script

After the script finishes running, press the Enter key to exit the script.

Summarize

In this article, we introduced how to quickly view the passwords of connected WiFi networks using a Python script. We took a sample script as an example and introduced step by step how to use the script to view WiFi passwords. If you forget your WiFi password, you can try this script to help you find the password. But it should be noted that this method is only applicable to the WiFi network that has been connected, if you have not connected to the WiFi network, you cannot view the password.
 

Guess you like

Origin blog.csdn.net/qq_43596041/article/details/129842702