Skip to content

Commit 3030551

Browse files
committed
improved overall script added new features
1 parent 6ef5d98 commit 3030551

File tree

1 file changed

+59
-22
lines changed

1 file changed

+59
-22
lines changed
Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,71 @@
1-
"""
2-
This scripts fetches all saved wifi passwords in your Windows PC
3-
"""
4-
1+
import os
2+
import platform
53
import subprocess
64

75

86
def get_all_profiles():
9-
try:
10-
data = subprocess.check_output(
11-
["netsh", "wlan", "show", "profiles", "key=clear"]
12-
).decode("utf-8", errors="backslashreplace")
13-
return data
14-
except FileNotFoundError:
7+
system = platform.system()
8+
if system == 'Windows':
9+
try:
10+
data = subprocess.check_output(
11+
["netsh", "wlan", "show", "profiles", "key=clear"]
12+
).decode("utf-8", errors="backslashreplace")
13+
return data
14+
except subprocess.CalledProcessError as error:
15+
return f"Error: {error}"
16+
else:
1517
return "Only For Windows"
1618

1719

1820
def get_profiles_info(profile):
19-
try:
20-
data = subprocess.check_output(
21-
["netsh", "wlan", "show", "profiles", profile, "key=clear"]
22-
).decode("utf-8", errors="backslashreplace")
23-
24-
return data
25-
except subprocess.CalledProcessError:
26-
return "Profile Not Found"
27-
except FileNotFoundError:
21+
system = platform.system()
22+
if system == 'Windows':
23+
try:
24+
data = subprocess.check_output(
25+
["netsh", "wlan", "show", "profiles", profile, "key=clear"]
26+
).decode("utf-8", errors="backslashreplace")
27+
return data
28+
except subprocess.CalledProcessError as error:
29+
return f"Error: {error}"
30+
else:
31+
return "Only For Windows"
32+
33+
34+
def output_to_file(file_path, data):
35+
with open(file_path, 'w') as f:
36+
f.write(data)
37+
38+
39+
def delete_profile(profile):
40+
system = platform.system()
41+
if system == 'Windows':
42+
try:
43+
subprocess.check_call(
44+
["netsh", "wlan", "delete", "profile", f"name=\"{profile}\""]
45+
)
46+
return f"{profile} profile deleted successfully"
47+
except subprocess.CalledProcessError as error:
48+
return f"Error: {error}"
49+
else:
2850
return "Only For Windows"
2951

3052

3153
if __name__ == "__main__":
32-
print(get_all_profiles())
33-
profile = input("Enter the profile Name: ")
34-
print(get_profiles_info(profile))
54+
print("Fetching all saved Wi-Fi profiles...")
55+
profiles = get_all_profiles()
56+
print(profiles)
57+
58+
if profiles != "Only For Windows":
59+
profile_name = input("Enter the profile name: ")
60+
profile_info = get_profiles_info(profile_name)
61+
print(profile_info)
62+
63+
output_choice = input("Do you want to output the results to a file? (y/n): ")
64+
if output_choice.lower() == 'y':
65+
file_path = input("Enter the file path to save the output: ")
66+
output_to_file(file_path, profile_info)
67+
68+
delete_choice = input("Do you want to delete this profile? (y/n): ")
69+
if delete_choice.lower() == 'y':
70+
delete_result = delete_profile(profile_name)
71+
print(delete_result)

0 commit comments

Comments
 (0)