-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathread_wifi_passwords.py
57 lines (41 loc) · 1.44 KB
/
read_wifi_passwords.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
import subprocess
from rich.console import Console
from rich.table import Table
def find_networks():
raw_output = subprocess.check_output(
['netsh', 'wlan', 'show', 'profiles'])
result = parse_output(raw_output, "All User Profile")
return result
def find_passwords(networks):
network_passwords = {}
for network in networks:
raw_output = subprocess.check_output(
['netsh', 'wlan', 'show', 'profiles', network, 'key=clear'])
result = parse_output(raw_output, "Key Content")
if len(result) == 1:
network_passwords[network] = result[0]
else:
network_passwords[network] = "***missing***"
return network_passwords
def parse_output(raw_output, identifier):
output = raw_output.decode('cp1252', errors="backslashreplace")
lines = output.split('\n')
matches = []
for line in lines:
if identifier in line:
parts = line.split(":")
value = parts[1][1:-1]
matches.append(value)
return matches
def display_networks(passwords):
table = Table(title="Wi-Fi network passwords")
table.add_column("Network")
table.add_column("Password")
for key, value in passwords.items():
table.add_row(key, value)
console = Console()
console.print(table)
if __name__ == '__main__':
networks = find_networks()
passwords = find_passwords(networks)
display_networks(passwords)