-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
141 lines (115 loc) · 4.42 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import subprocess
import locale
import ctypes
import tkinter as tk
from tkinter import ttk
def get_system_language():
"""
Get the language of the system
:return:
"""
windll = ctypes.windll.kernel32
windll.GetUserDefaultUILanguage()
language = locale.windows_locale[windll.GetUserDefaultUILanguage()]
return language
def get_wlan_ssid(language):
"""
Get the SSID of the available networks using the netsh command
:param language: The language of the system
:return:
"""
data = subprocess.check_output(
['netsh', 'wlan', 'show', 'profiles']
).decode('utf-8', errors="backslashreplace").split('\n')
if language == "fr_FR":
profiles = [i.split(':')[1][1:-1] for i in data if "Profil Tous les utilisateurs" in i]
if language == "en_US":
profiles = [i.split(':')[1][1:-1] for i in data if "All User Profile" in i]
ssid_list = []
for i in profiles:
if "\\" in i:
continue
else:
ssid = None
profile_info = subprocess.check_output(
['netsh', 'wlan', 'show', 'profile', 'name=' + i, 'key=clear']
).decode('utf-8', errors="backslashreplace").split('\n')
if language == "fr_FR":
for a in profile_info:
if "Nom du SSID" in a:
ssid = a.split(':')[1][2:-2]
break
ssid = "No SSID found" if ssid is None else ssid
ssid_list.append(ssid)
if language == "en_US":
for a in profile_info:
if "SSID name" in a:
ssid = a.split(':')[1][2:-2]
break
ssid = "No SSID found" if ssid is None else ssid
ssid_list.append(ssid)
return ssid_list
def get_wlan_infos(ssid, language):
"""
Get the password and the authentication type of the selected SSID
:param ssid: The SSID of the network
:param language: The language of the system
"""
key_content = None
auth_type = None
profile_info = subprocess.check_output(
['netsh', 'wlan', 'show', 'profile', 'name=' + ssid, 'key=clear']
).decode('utf-8', errors="backslashreplace").split('\n')
if language == "fr_FR":
for a in profile_info:
if "Contenu de la cl" in a:
key_content = a.split(':')[1][1:-1]
key_content = "No password found" if key_content is None else key_content
if "Authentification" in a:
auth_type = a.split(':')[1][1:-1].split('\\xff')[0]
auth_type = "No authentication type found" if auth_type is None else auth_type
if language == "en_US":
for a in profile_info:
if "Key content" in a:
key_content = a.split(':')[1][1:-1]
key_content = "No password found" if key_content is None else key_content
if "Authentication" in a:
auth_type = a.split(':')[1][1:-1].split('\\xff')[0]
auth_type = "No authentication type found" if auth_type is None else auth_type
return key_content, auth_type
def print_infos(infos, ssid_combo, language):
"""
Print the password and the authentication type of the selected SSID
:param infos: The text widget
:param ssid_combo: The combobox widget
"""
infos.delete('1.0', tk.END)
infos.insert(tk.END, f"\nSSID: {ssid_combo.get()}\nPassword: {get_wlan_infos(ssid_combo.get(), language)[0]}\n"
f"Authentication type: {get_wlan_infos(ssid_combo.get(), language)[1]}", "center")
def script_ui():
"""
Create the UI
"""
root = tk.Tk()
root.title("Wifi Password Viewer")
root.geometry("500x200")
root.resizable(False, False)
supported_language_list = ["fr_FR", "en_US"]
if get_system_language() not in supported_language_list:
print("Your language is not supported yet")
exit()
ssid_list = get_wlan_ssid(get_system_language())
ssid_list.sort()
ssid_combo = ttk.Combobox(root, values=ssid_list, state="readonly")
ssid_combo.pack(pady=10)
infos = tk.Text(root, height=5, width=50)
infos.tag_configure("center", justify='center')
ssid_combo.bind("<<ComboboxSelected>>", lambda e: print_infos(infos, ssid_combo, get_system_language()))
infos.pack()
root.mainloop()
def main():
"""
Main function
"""
script_ui()
main()