Getting Saved Wifi Passwords using Python
Usually while connecting with the wifi we have to enter some password to access the network, but we are not directly able to see the password we have entered earlier i.e password of saved network. In this article, we will see how we can get all the saved WiFi name and passwords using Python, in order to do this we will use subprocess module of python.
Wi-Fi is a wireless networking technology that allows devices such as computers (laptops and desktops), mobile devices (smartphones and wearables), and other equipment (printers and video cameras) to interface with the Internet.
The subprocess module present in Python(both 2.x and 3.x) is used to run new applications or programs through Python code by creating new processes. It also helps to obtain the input/output/error pipes as well as the exit codes of various commands.
Steps for Implementation :
1. Import the subprocess module
2. Get the metadata of the wlan(wifi) with the help of check_output method
3. Decode the metadata and split the meta data according to the line
4. From the decoded metadata get the names of the saved wlan networks
5. Now for each name again get the metadata of wlan according to the name
6. Start try and catch block and inside the try block, decode and split this metadata and get the password of the given wifi name
7. Print the password and the wifi name and print blank if there is no password
8. In except block if process error occurred print encoding error occurred
Below is the implementation
Python3
import subprocess
meta_data = subprocess.check_output([ 'netsh' , 'wlan' , 'show' , 'profiles' ])
data = meta_data.decode( 'utf-8' , errors = "backslashreplace" )
data = data.split( '\n' )
profiles = []
for i in data:
if "All User Profile" in i :
i = i.split( ":" )
i = i[ 1 ]
i = i[ 1 : - 1 ]
profiles.append(i)
print ( "{:<30}| {:<}" . format ( "Wi-Fi Name" , "Password" ))
print ( "----------------------------------------------" )
for i in profiles:
try :
results = subprocess.check_output([ 'netsh' , 'wlan' , 'show' , 'profile' , i, 'key = clear' ])
results = results.decode( 'utf-8' , errors = "backslashreplace" )
results = results.split( '\n' )
results = [b.split( ":" )[ 1 ][ 1 : - 1 ] for b in results if "Key Content" in b]
try :
print ( "{:<30}| {:<}" . format (i, results[ 0 ]))
except IndexError:
print ( "{:<30}| {:<}" . format (i, ""))
except subprocess.CalledProcessError:
print ( "Encoding Error Occurred" )
|
Output :
Wi-Fi Name | Password
-----------------------------------------------
Engineer | ayush123
honor | 1234567890
Engineer_5GHz | ayush123
Redmi | 12345677
Ayush | 123123123
BiGX-cmtqaGFtYjc | rakshit123
UERJTTBV8e0GUmVkbWkg 2 | 987654321
DESKTOP-F32H70N 5009 | SUSHANT@123
UERJTTBV8e0GUmVkbWkg |
Bunns | heyhotspot
Hogwarts | sushant@123
Cgc wireless | database1234
Moto G (5) Plus 8691 | rakshit123
AndroidAP | udrw7859
AndroidAPab7e | 123000123
roshan | 12345678
Svj? | salonivij
Hey | heythere
AndroidAP202 | bhuvanbroo
JARVIS | abhishek09
B6NO-wq5hamF0IGt1bWHCrg | 12345678
CDAC |
Last Updated :
10 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...