Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb03f829

Browse files
authored
Fix: Edited the text.
Edited the text to make it a bit more readable and consistent. Also changed list() and dict() to [] and {}.
1 parentb57415a commitb03f829

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

‎windows10-wifi.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,70 @@
44
#https://www.youtube.com/davidbombal #
55
######################################
66

7-
# Import subprocess so we can use system commands
7+
#Import subprocess so we can use system commands.
88
importsubprocess
99

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.
1111
importre
1212

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.
2326
command_output=subprocess.run(["netsh","wlan","show","profiles"],capture_output=True).stdout.decode()
2427

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.
2832
profile_names= (re.findall("All User Profile : (.*)\r",command_output))
2933

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=[]
3337

34-
#If we didn't findprofile nameswe didn't have anywifi 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 anyprofile namesare not found this means thatwifi connections
39+
# have also not been found. So we run this part to check the
40+
# details of the wifi and seewhether we can get their passwords.
3741
iflen(profile_names)!=0:
3842
fornameinprofile_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.
4349
profile_info=subprocess.run(["netsh","wlan","show","profile",name],capture_output=True).stdout.decode()
44-
# We usea regular expression to only look for the absent cases so we can ignore them.
50+
#We usethe regular expression to only look for the absent cases so we can ignore them.
4551
ifre.search("Security key : Absent",profile_info):
4652
continue
4753
else:
48-
# Assign the ssid of the wifi profile to the dictionary
54+
#Assign the ssid of the wifi profile to the dictionary.
4955
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.
5158
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).
5361
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.
5564
ifpassword==None:
5665
wifi_profile["password"]=None
5766
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.
5969
wifi_profile["password"]=password[1]
60-
# We append the wifi information to the wifi_list
70+
#We append the wifi information to thevariablewifi_list.
6171
wifi_list.append(wifi_profile)
6272

6373
forxinrange(len(wifi_list)):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp