Get WiFi passwords in Windows using Python

How to retrieve WiFi passwords in Windows using Python?

To retrieve wifi passwords in windows using Python, we’ll use Python’s subprocess module, which allows us to run (cmd) command prompt commands inside our application, making it simple to check the stored wifi passwords in your system.

With python already installed, this script searches Windows for wifi passwords and displays them beside the network name. It will search for only those passwords that your computer already knows. In the event that you forget your WiFi password, this script will come in handy.

retrieve wifi passwords in windows using Python

This article shows how to use python to analyze netsh commands to find passwords on a Windows machine. If you forget your wifi password but your machine is connected, it is simple to recover it.

Steps through which you can retrieve WiFi passwords in Windows using Python.

  • Import subprocess module
  • Run the first command using the subprocess.check_output() method and store the profiles data in a variable.
  • Convert the profile data into a list
  • Iterate over the list and run the second command to check the passwords.
  • Store the passwords and print.

import subprocess

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]
for i in profiles:
        results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8', errors="backslashreplace").split('\n')
        results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b]
            print ("{:<30}|  {:<}".format(i, results[0]))
        except IndexError:
            print ("{:<30}|  {:<}".format(i, ""))
    except subprocess.CalledProcessError:
        print ("{:<30}|  {:<}".format(i, "ENCODING ERROR"))


It will only work in the English language. This is due to the fact that strings like “Key Content” may alter in different languages.

You’ll need to determine the strings we’re looking for in your current language and replace them in the script to correct this.