-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowWifiPassword.py
66 lines (48 loc) · 1.81 KB
/
ShowWifiPassword.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# importing subprocess
import subprocess
# getting meta data
meta_data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles'])
# decoding meta data
data = meta_data.decode('utf-8', errors="backslashreplace")
# splitting data by line by line
data = data.split('\n')
# creating a list of profiles
profiles = []
# traverse the data
for i in data:
# find "All User Profile" in each item
if "All User Profile" in i:
# if found
# split the item
i = i.split(":")
# item at index 1 will be the wifi name
i = i[1]
# formatting the name
# first and last character are useless
i = i[1:-1]
# appending the wifi name to the list
profiles.append(i)
# printing heading
print("{:<30}| {:<}".format("Wi-Fi Name", "Password"))
print("----------------------------------------------")
# traversing the profiles
for i in profiles:
# try-except block begins
# try block
try:
# getting meta data with password using wifi name
results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear'])
# decoding and splitting data line by line
results = results.decode('utf-8', errors="backslashreplace")
results = results.split('\n')
# finding password from the result list
results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b]
# if there is a password, it will print the password
try:
print("{:<30}| {:<}".format(i, results[0]))
# else it will print blank in front of the password
except IndexError:
print("{:<30}| {:<}".format(i, ""))
# called when this process fails
except Exception as e:
print("Error Occurred:", e)