|
4 | 4 | #https://www.youtube.com/davidbombal #
|
5 | 5 | ######################################
|
6 | 6 |
|
7 |
| -# Import subprocess so we can use system commands |
| 7 | +# Import subprocess so we can use system commands. |
8 | 8 | import subprocess
|
9 | 9 |
|
10 |
| -# Import the re module so that we can make use of regular expressions. |
| 10 | +# Import the re module so we can make use of regular expressions. |
11 | 11 | import re
|
12 | 12 |
|
13 |
| -# Python allows us to run system commands by using a function provided by the subprocess module |
14 |
| -# (subprocess.run(<list of command line arguments goes here>, <specify the second argument if you want to capture the output>)) |
15 |
| -# The script is a parent process and creates a child process which runs the system command, |
16 |
| -# and will only continue once the child process has completed. |
17 |
| -# To save the contents that gets sent to the standard output stream (the terminal) |
18 |
| -# we have to specify that we want to capture the output, |
19 |
| -# so we specify the second argument as capture_output = True. |
20 |
| -# This information gets stored in the stdout attribute. |
21 |
| -# The information is stored in bytes and we need to decode it to Unicode |
22 |
| -# before we use it as a String in Python. |
| 13 | +# Python allows us to run system commands using the function |
| 14 | +# provided by the subprocess module; |
| 15 | +# (subprocess.run(<list of command line arguments go here>, <specify the second argument if you want to capture the output>)). |
| 16 | +# |
| 17 | +# This script is a parent process that creates a child process which |
| 18 | +# runs a system command and will only continue once the child process |
| 19 | +# is completed. |
| 20 | +# |
| 21 | +# To save the contents that get sent to the standard output stream |
| 22 | +# (the terminal), we must first specify that we want to capture the output. |
| 23 | +# To do this we specify the second argument as capture_output = True. |
| 24 | +# This information gets stored in the stdout attribute as bytes and |
| 25 | +# needs to be decoded before being used as a String in Python. |
23 | 26 | command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode()
|
24 | 27 |
|
25 |
| -# We imported the re module so that we can make use of regular expressions. |
26 |
| -# We want to find all the Wifi names which is always listed after "ALL User Profile :". |
27 |
| -# In the regular expression we create a group of all characters until the return escape sequence (\r) appears. |
| 28 | +# We imported the re module to make use of regular expressions. |
| 29 | +# We want to find all the wifi names which are listed after |
| 30 | +# "ALL User Profile :". Using regular expressions we can create |
| 31 | +# a group of all characters until the return escape sequence (\r) appears. |
28 | 32 | profile_names = (re.findall("All User Profile : (.*)\r", command_output))
|
29 | 33 |
|
30 |
| -# We create an empty list outside of the loop where dictionaries with all the wifi |
31 |
| -# username and passwords will be saved. |
32 |
| -wifi_list = list() |
| 34 | +# We create an empty list outside of the loop where dictionaries |
| 35 | +# containing all the wifi usernames and passwords will be saved. |
| 36 | +wifi_list = [] |
33 | 37 |
|
34 |
| -# If we didn't find profile names we didn't have any wifi connections, |
35 |
| -# so we only run the part to check for the details of the wifi and |
36 |
| -# whether we can get their passwords in this part. |
| 38 | +# If any profile names are not found this means that wifi connections |
| 39 | +# have also not been found. So we run this part to check the |
| 40 | +# details of the wifi and see whether we can get their passwords. |
37 | 41 | if len(profile_names) != 0:
|
38 | 42 | for name in profile_names:
|
39 |
| - # Every wifi connection will need its own dictionary which will be appended to the wifi_list |
40 |
| - wifi_profile = dict() |
41 |
| - # We now run a more specific command to see the information about the specific wifi connection |
42 |
| - # and if the Security key is not absent we can possibly get the password. |
| 43 | + # Every wifi connection will need its own dictionary which |
| 44 | + # will be appended to the variable wifi_list. |
| 45 | + wifi_profile = {} |
| 46 | + # We can now run a more specific command to see the information |
| 47 | + # about the wifi connection and if the Security key |
| 48 | + # is not absent it may be possible to get the password. |
43 | 49 | profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output = True).stdout.decode()
|
44 |
| - # We use a regular expression to only look for the absent cases so we can ignore them. |
| 50 | + # We use the regular expression to only look for the absent cases so we can ignore them. |
45 | 51 | if re.search("Security key : Absent", profile_info):
|
46 | 52 | continue
|
47 | 53 | else:
|
48 |
| - # Assign the ssid of the wifi profile to the dictionary |
| 54 | + # Assign the ssid of the wifi profile to the dictionary. |
49 | 55 | wifi_profile["ssid"] = name
|
50 |
| - # These cases aren't absent and we should run them "key=clear" command part to get the password |
| 56 | + # These cases aren't absent and we should run the |
| 57 | + # "key=clear" command part to get the password. |
51 | 58 | profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output = True).stdout.decode()
|
52 |
| - # Again run the regular expressions to capture the group after the : which is the password |
| 59 | + # Again run the regular expression to capture the |
| 60 | + # group after the : (which is the password). |
53 | 61 | password = re.search("Key Content : (.*)\r", profile_info_pass)
|
54 |
| - # Check if we found a password in the regular expression. All wifi connections will not have passwords. |
| 62 | + # Check if we found a password using the regular expression. |
| 63 | + # Some wifi connections may not have passwords. |
55 | 64 | if password == None:
|
56 | 65 | wifi_profile["password"] = None
|
57 | 66 | else:
|
58 |
| - # We assign the grouping (Where the password is contained) we are interested to the password key in the dictionary. |
| 67 | + # We assign the grouping (where the password is contained) that |
| 68 | + # we are interested in to the password key in the dictionary. |
59 | 69 | wifi_profile["password"] = password[1]
|
60 |
| - # We append the wifi information to the wifi_list |
| 70 | + # We append the wifi information to the variable wifi_list. |
61 | 71 | wifi_list.append(wifi_profile)
|
62 | 72 |
|
63 | 73 | for x in range(len(wifi_list)):
|
|
0 commit comments