Skip to content

Commit f41a498

Browse files
authored
Merge pull request #273 from LpCodes/wifipassword
improved overall script added new features
2 parents c0e2df5 + c62c32b commit f41a498

File tree

2 files changed

+84
-30
lines changed

2 files changed

+84
-30
lines changed
+25-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
1-
import string #String module will import all the nessary ascii character
2-
import random #random module help us to import functions needed to generate random element.
1+
import string
2+
import secrets
33

4-
passwrd = string.ascii_letters+string.digits+string.punctuation #This will generate a string consist of all ascii character.
4+
# Define the set of characters to be used in the password
5+
CHARACTER_SET = string.ascii_letters + string.digits + string.punctuation
56

6-
numPass = int(input("How many passwords do you need to be generated? "))
7-
length = int(input("Enter the length of the password(s): "))
7+
def generate_password(length):
8+
"""Generate a random password of the specified length."""
9+
password = ''.join(secrets.choice(CHARACTER_SET) for i in range(length))
10+
return password
811

9-
print("List(s) of Generated passwords: ")
12+
def main():
13+
# Prompt the user for the number of passwords to generate and their length
14+
while True:
15+
try:
16+
num_pass = int(input("How many passwords do you want to generate? "))
17+
password_length = int(input("Enter the length of the password(s): "))
18+
break
19+
except ValueError:
20+
print("Please enter a valid integer.")
1021

11-
for _ in range(numPass):
12-
print(''.join(random.sample(passwrd, k=length))) #sample() generates an array of random characters of length k
22+
# Generate the specified number of passwords and print them to the console
23+
print("Generated passwords:")
24+
for i in range(num_pass):
25+
password = generate_password(password_length)
26+
print(f"{i+1}. {password}")
27+
28+
if __name__ == "__main__":
29+
main()
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)