Get WiFi Password using Python Code | Windows 10 and 11 | Updated 2023
Get WiFi Password using Python Code For Windows 11 and Windows 10
This Python script retrieves the names of all wireless network profiles stored on the computer and the associated password for each profile.
The script uses the subprocess module, which allows the script to run shell commands.
The first line of the script retrieves a list of all the wireless network profiles by running the shell command netsh wlan show profiles. The output of the shell command is decoded as a utf-8 string and stored in the data variable.
The list of profiles is then extracted from the data variable and stored in the profiles list. The profiles are obtained by searching for the string "All User Profile" in each line of data and extracting the profile name, which follows the string ":".
For each profile in profiles, the script retrieves the password for the profile by running the shell command netsh wlan show profile <profile name> key=clear. The output of this command is decoded as a utf-8 string and stored in the results variable.
The password is then extracted from the results and printed, along with the profile name. If the password cannot be found, an empty string is printed. If there is an encoding error in the output of the shell command, the string "ENCODING ERROR" is printed.
Finally, the script waits for user input by calling the input function.
import subprocess
def get_wifi_profiles():
try:
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8', errors="backslashreplace").split('\n')
profiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i]
profile_data = {}
for profile in profiles:
try:
results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', profile, 'key=clear']).decode('utf-8', errors="backslashreplace").split('\n')
password = [b.split(":")[1][1:-1] for b in results if "Key Content" in b]
if password:
profile_data[profile] = password[0]
else:
profile_data[profile] = "No password found"
except subprocess.CalledProcessError as e:
profile_data[profile] = str(e)
return profile_data
except Exception as e:
return str(e)
profile_data = get_wifi_profiles()
for profile, password in profile_data.items():
print("{:<30 code="" format="" password="" profile="">30>