Не определяет русскую раскладку SOCKET CMD

Рейтинг: 0Ответов: 1Опубликовано: 07.07.2023

Server:

import socket

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('0.0.0.0', 8081))
server.listen()


print(f"Server started! ip: 00000")
con, add = server.accept()

while True:
    command = input('[~] ')
    con.send(command.encode("utf-8"))

    response = con.recv(2048).decode("utf-8")
    print('[>] ', response)

Клиент:

import socket
import subprocess
import time

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)


client.connect(("0.0.0.0", 8081))
print('Connected!')

while True:
    command = client.recv(2048).decode("utf-8")
    result = subprocess.getoutput(command)
    client.send(result.encode("utf-8"))

При запросе любой команды, русские буквы в ответе, превращаются в - ’®¬ ў гбва®©б⢥ C ­Ґ Ё¬ҐҐв ¬ҐвЄЁ. ‘ҐаЁ©­л© ­®¬Ґа ⮬ : 8C97-B892

Ответы

▲ 0Принят

Спасибо за ответ - @gord1402

process = subprocess.Popen(['cmd', '/C', command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = process.communicate()
send_bites(client, out.decode('cp866').encode('utf-8'))