-
Notifications
You must be signed in to change notification settings - Fork 0
/
wlan-fetcher-version2.py
49 lines (37 loc) · 1.32 KB
/
wlan-fetcher-version2.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
# -*- coding: utf-8 -*-
from __future__ import annotations
from subprocess import check_output, CalledProcessError
from re import findall, search
# EDITABLES
PROFILES_KEYWORD = "Profile"
KEY_CONTENT_KEYWORD = "Key Content"
def wifi_passwords(
profiles_keyword: str = "Profile",
key_content_keyword: str = "Key Content",
return_errors: bool = False,
) -> dict | tuple[dict, list]:
data = {}
errors = []
profiles_command = "netsh wlan show profiles"
key_command = "netsh wlan show profiles name='{key}' key=clear"
networks = check_output(
profiles_command,
shell=True
).decode("utf-8", "replace")
for network in findall(f"(?:{profiles_keyword}\s*:\s)(.*)", networks):
network = network.split('\r')[0]
try:
result = check_output(
key_command.format(key=network),
shell=True
).decode("utf-8", "ignore")
except CalledProcessError:
errors += [network]
continue
password = search(f"(?:{key_content_keyword}\s*:\s)(.*)", result)
data[network] = password[1]
if return_errors:
return data, errors
return data
if __name__ == "__main__":
print(wifi_passwords(PROFILES_KEYWORD,KEY_CONTENT_KEYWORD,True))