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
- Get the output for the command "netsh wlan show profiles".
- Decode the output into "utf-8".
- Split the string into a single separate string.
- Now we have a list of string.
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n')
Step. 3
- Get the lines that only contain "All User Profile".
- Split it by ":".
- 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)
- Now we have the variable with the WiFi profile names.
- 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)
- 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)
- Print out the results of stored wi-fi password.
try:
print("{:<30} | {:<}".format(i, results[0]))
except IndexError:
print("{:<30} | {:<}".format(i, ""))
Step. 7
- 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
- Net VN (Producer), (2019, November 22nd), Show all Wi-Fi Password | Windows 10 / 8.1 / 8.7, [Youtube]. Retrieve from https://www.youtube.com/watch?v=kQs1s_kqmnk
- PyTutorial (Producer), (2018, May 10th), Get Stored WIFI Passwords With Python, [Youtube]. Retrieve from https://www.youtube.com/watch?v=j7ysqGXFJKU
- Get WiFi Passwords With Python, [Web blog message]. Retrieve from https://nitratine.net/blog/post/get-wifi-passwords-with-python/
- Netsh Command Syntax, Contexts, and Formatting, [Web blog message].Retrieve from https://docs.microsoft.com/zh-tw/windows-server/networking/technologies/netsh/netsh-contexts
Thanks for listening.
Get Stored WI-FI Password with python for windows
By Иo1lz
Get Stored WI-FI Password with python for windows
- 86