T
T
Tihon492019-06-26 11:55:35
Python
Tihon49, 2019-06-26 11:55:35

How to read python DOS(?) encoding?

There is a python script that recognizes all wi-fi points to which the computer / laptop was connected, then writes the output of the cmd commands "netsh wlan show profile name=Some_SSID_name key=clear" to a .txt file. But when I open the .txt file, I see
this :
--------------------- : €da bvagЄvga  'ЁЇ a ¤Ё®bҐвЁ: [ «оЎ®© ВЁЇ a ¤Ё®bҐвЁ] ђ biЁаҐЁҐ Ї®bv ўyЁЄ: ®vbgvbvўgҐv P a --¬Ґval ЎҐ-§®Ї bv ---------------- WPA2-Personal Food: CCMP WPA2-Personal Food: GCMP
Љ«oz ЎҐ§®Ї b®bvЁ: ЏаЁbgvbvўgҐv
'®¤Ґа¦Ё¬®Ґ Є«oz : UberMan2000
In principle, I successfully get the names of points and passwords, but how can I recode it so that it doesn’t hurt my eyes?
the script code itself:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import subprocess
import os
 
 
my_list = []
 
with open('Output.txt', 'w') as file:
    subprocess.run('netsh wlan show profiles', stdout=file, check=True)
 
with open('Output.txt') as file:
    lines = file.readlines()
    lines = str(lines)
    for line in lines.split(','):
        for i in line.split(':'):
            my_list.append(i)
   
with open('SSID.txt', 'a') as file:
    for i in my_list[11::2]:
        file.write(i.replace("\\n'", '').replace(' ', '') + '\n')
 
with open('SSID.txt') as f:
    lines = f.readlines()
    for line in lines:
        line = line.split()
        # print(f'netsh wlan show profile name={line[0]} key=clear')
        with open('Good.txt', 'a') as file:
            try:
                subprocess.run(f'netsh wlan show profile name={line[0]} key=clear', stdout=file, check=True)
            except:
                pass
 
os.system('del Output.txt')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey S., 2019-06-26
@Tihon49

with open('Output.txt', encoding='cp866') as file:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question