Get Stored WI-FI Password

with python for windows

Lecturer: Иo1lz

Time: Oct. 11th, 2020

Outline

  • Introduction
  • Lab
  • References

Introduction

About netsh

  • Network shell (netsh) is a command-line utility that allows you to configure and display the status of various network communications server roles and components
  • Netsh interacts with other operating system components by using dynamic-link library (DLL) files.

About netsh

  • "netsh wlan show profiles"
    • show the profiles for wifi connection the computer has stored.
  • "netsh wlan show profile {Profile Name} key=clear"
    • output contain the network key (which is wifi password)

Lab

Step. 0

Create a file with a filename extension of ".py" and any filename you like.

Step. 1

This module can interact with cmd.

import subprocess

Step. 2

  1. Get the output for the command "netsh wlan show profiles".
  2. Decode the output into "utf-8".
  3. Split the string into a single separate string.
  4. Now we have a list of string.
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n')

Step. 3

  1. Get the lines that only contain "All User Profile".
  2. Split it by ":".
  3. Get the right hand side and remove the first and the last character.
profiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i]

Step. 4 (in loop)

  1. Now we have the variable with the WiFi profile names.
  2. Get the output command "netsh wlan show profile {profile name} key=clear"
for i in profiles:
  results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').split('\n')

Step. 5 (in loop)

  1. Find the line that contain "Key Content" and split the string like before
  results = [k.split(":")[1][1:-1] for k in results if "Key Content" in k]

Step. 6 (in loop)

  1. Print out the results of stored wi-fi password.
  try:
    print("{:<30} | {:<}".format(i, results[0]))
  except IndexError:
    print("{:<30} | {:<}".format(i, ""))

Step. 7

  1. The program would not stop immediately when the result show up.
input("")
import subprocess

data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').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').split('\n')
  results = [k.split(':')[1][1:-1] for k in results if "Key Content" in k]
  try:
    print("{:<30} | {:<}".format(i, results[0]))
  except IndexError:
    print("{:<30} | {:<}".format(i, ""))
input("")
import subprocess

data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n')
profiles = [i.split(':')[1][1:-1] for i in data if "All User Profile" in i]

for i in profiles:
  try:
    results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').split('\n')
    results = [k.split(':')[1][1:-1] for k in results if "Key Content" in k]
    try:
      print("{:<30} | {:<}".format(i, results[0]))
    except IndexError:
      print("{:<30} | {:<}".format(i, ""))
  except subprocess.CallProcessError:
    print("{:<30} | {:<}".format(i, "ENCODING ERROR!"))
input("")

References

Thanks for listening.

Get Stored WI-FI Password with python for windows

By Иo1lz

Get Stored WI-FI Password with python for windows

  • 86