import subprocess
def get_wifi_password():
try:
# Run the command to retrieve Wi-Fi profiles
profiles = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n')
profile_names = [line.split(':')[1].strip() for line in profiles if "All User Profile" in line]
passwords = {}
# Retrieve the Wi-Fi password for each profile
for name in profile_names:
try:
result = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', name, 'key=clear']).decode('utf-8').split('\n')
password_line = [line.split(':')[1].strip() for line in result if "Key Content" in line]
if password_line:
passwords[name] = password_line[0]
except subprocess.CalledProcessError as e:
print(f"Failed to retrieve password for profile '{name}': {e}")
return passwords
except subprocess.CalledProcessError as e:
print(f"Failed to retrieve Wi-Fi profiles: {e}")
# Usage
wifi_passwords = get_wifi_password()
for name, password in wifi_passwords.items():
print(f"Wi-Fi Network: {name}\nPassword: {password}\n")
Comments
Post a Comment