How to check saved password in wifi network using Python 3


This tutorial will show you how to check saved password in wifi network using Python 3. It’s for your experiment purpose only and it does not retrieve your forgotten password from wifi network.

Problem Scenario

Suppose you have saved your wifi network password and every time you connect to the wifi network you don’t need to input password but it connects automatically due to your saved password.

Now you may have the situation when you need to change or reset the wifi network password for some reasons but you don’t remember the password. Therefore you need to know the wifi network password before you can reset or update the existing password. So this example will help you to retrieve the saved password in wifi network using Python 3.

So let’s move on to the next step…


Have Python installed in Windows (or Unix)
Pyhton version and Packages
Here I am using Python 3.6.6 version

Example with Source Code

Subprocess Module

We have first imported the required module subprocess. The subprocess module allows you to spawn new processes, connect to input/output/error pipes, and obtain their return codes.

The format of subprocess.check_output API is similar to below:

subprocess.check_output(args, *, stdin=None, stderr=None, shell=False, cwd=None, encoding=None, errors=None, universal_newlines=False, timeout=None)

By default, the above function will return the data as encoded bytes. The actual encoding of the output data may depend on the command being invoked, so the decoding to text will often need to be handled at the application level.

Additional Command

We have used command netsh wlan show profiles in our Python script to retrieve the stored key from profiles. It will retrieve all keys stored for all profiles in your system. If you have only one profile then it will retrieve for only one profile.

Netsh is a command-line scripting utility that allows you to display or modify the network configuration of a computer that is currently running.

WLAN commands that allow you to access the Wi-Fi profiles.

Show the list of wireless profiles.

Then we basically split, extract and format to print the user name and password of the wifi network for profiles.

import subprocess

a = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('n')
a = [i.split(":")[1][1:-1] for i in a if "All User Profile" in i]
for i in a:
    results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').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, ""))

Now run the above Python script to check saved password in wifi network for your profile.

Source Code

You can download source code.

Thanks for reading.

Related posts

Leave a Comment