-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
180 lines (147 loc) · 5.68 KB
/
main.py
File metadata and controls
180 lines (147 loc) · 5.68 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import subprocess
import customtkinter as ctk
from subprocess import CalledProcessError
class RetriveConnectedWifiPasswordApp:
def __init__(self) -> None:
self.root = ctk.CTk()
self.app_width = 700
self.app_height = 680
self.color1 = "#D2DE32"
self.color2 = "#FFFFDD"
self.bgcolor = "#61A3BA"
# icon_path = "icons8-wifi-96.ico"
# self.root.iconbitmap(icon_path)
self.screenwidth = self.root.winfo_screenwidth()
self.screenheight = self.root.winfo_screenheight()
self.x = (self.screenwidth // 2) - (self.app_width // 2) + 120
self.y = (self.screenheight // 2) - (self.app_height // 2) - 38
self.root.title("Get Connected Wi-Fi Password")
self.root.geometry(f"{self.app_width}x{self.app_height}+{self.x}+{self.y}")
self.root.resizable(False, False)
self.root.configure(bg=self.bgcolor)
self.header = None
self.scrollable = None
self.letsGoButton = None
self.resultLabel = None
self.data = {}
@staticmethod
def get_password(name: str) -> str:
try:
command = f'netsh wlan show profiles name="{name}" key=clear | findstr Key'
try:
output = (subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT).decode("utf-8").strip())
except UnicodeDecodeError:
output = (subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, encoding="latin-1").strip())
if "Key Content" in output:
password = output.split(":")[1].strip()
return password
else:
return None
except CalledProcessError as e:
print(f"Error: {e}")
print(f"Command output: {e.output.decode('utf-8').strip()}")
@staticmethod
def get_all_connected_wifi_profile() -> list[str]:
command = f"netsh wlan show profiles"
try:
all_wifis = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT).decode("utf-8")
except UnicodeDecodeError:
all_wifis = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT, encoding="latin-1")
except CalledProcessError as e:
print(f"Error: {e}")
print(f"Command output: {e.output.decode('utf-8').strip()}")
"""
# all_wifis looks like this
Profiles on interface Wi-Fi:
Group policy profiles (read only)
---------------------------------
<None>
User profiles
-------------
All User Profile : cencored1
All User Profile : cencored2
All User Profile : cencored3
All User Profile : cencored4
All User Profile : TP-Link_3E16
All User Profile : Redmi Note 9 Pro
All User Profile : TP-LINK_C32E7E
"""
profiles = [
line.split(":")[1].strip()
for line in all_wifis.split("\n")
if "All User Profile" in line
]
return profiles
def letsGoButtonEvent(self):
self.letsGoButton.configure(state="disabled")
all_profiles = self.get_all_connected_wifi_profile()
labelHeader = ctk.CTkLabel(
self.scrollable,
text="Connected Networks",
font=("Arial", 18, "bold"),
# bg_color="#555555",
# text_color="#FFFFFF",
width=200,
)
labelHeader.pack(side="top", pady=(8, 10))
for i, network in enumerate(all_profiles):
password = self.get_password(network)
# write data
self.data[network] = password
if password == None:
password = str(password).lower()
else:
password = "[" + password + "]"
text = network.rjust(40, " ") + " --> " + password.ljust(40, " ")
container = ctk.CTkFrame(self.scrollable)
if i + 1 == len(all_profiles):
container.pack(side="top", pady=(0, 16))
else:
container.pack(side="top")
number = ctk.CTkLabel(
container,
text=f"{(str(i+1) + ' ').rjust(5, ' ')}",
font=("Consolas", 11, "bold"),
# bg_color="#555555",
)
number.pack(side="left", pady=(0, 2), padx=(0, 2))
label = ctk.CTkLabel(
container,
text=text,
font=("Consolas", 11),
# bg_color="#555555",
width=200,
)
label.pack(side="left", pady=(0, 2))
self.root.update()
def initialize(self):
self.header = ctk.CTkLabel(
self.root,
text="Get Connected Wi-Fi Password",
font=("Arial", 26, "bold"),
# bg_color=self.color1,
# text_color="#000000",
width=self.screenwidth,
height=30,
)
self.header.pack(pady=(24, 0))
self.scrollable = ctk.CTkScrollableFrame(
self.root, width=self.app_width - 100, height=500
)
self.scrollable.pack(pady=(24, 0))
self.letsGoButton = ctk.CTkButton(
self.root,
text="Let's go",
command=self.letsGoButtonEvent,
font=("Arial", 12, "bold"),
width=150,
height=34,
corner_radius=18,
)
self.letsGoButton.pack(side="top", pady=(24, 0))
def run(self):
self.initialize()
self.root.mainloop()
if __name__ == "__main__":
app = RetriveConnectedWifiPasswordApp()
app.run()