0
votes

I want to create a program that decodes wifi passwords. I am not finished yet, but the program should print the names of all wifis. But there is an error and i dont know how to fix it.

import subprocess

data = subprocess.check_output(["netsh", "wlan", "show", "profiles"]).decode("utf-8").split("\n")
wifis = [line.split(":")(1)[1:-1] for line in data if "All User Profile" in line]
print (data)

data = subprocess.check_output(["netsh", "wlan", "show", "profiles"]).decode("utf-8").split(UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 76: invalid start byte

1

1 Answers

1
votes

netsh is a hint that you are using a Windows system. The console applications often use cp850 encoding for West European languages. So you could try :

data = subprocess.check_output(["netsh", "wlan", "show", "profiles"]).decode("cp850").split("\n")

Or to be safe you can use an encoding able to accept any input byte like latin1 but it seldom returns the expected characters on Windows. But NEVER use utf-8 when the input is not utf-8 encoded.