基础示例
# 服务端 from socket import * sk = socket() sk.bind((‘127.0.0.1‘,8090)) sk.listen() conn,addr = sk.accept() while True: cmd = input(‘>>>‘) if cmd == ‘q‘: conn.send(cmd.encode(‘utf-8‘)) break conn.send(cmd.encode(‘utf-8‘)) print(conn.recv(1024).decode(‘gbk‘)) conn.close() sk.close() # 客户端 from socket import * from subprocess import * ck = socket() ck.connect((‘127.0.0.1‘,8090)) while True: cmd = ck.recv(1024).decode(‘utf-8‘) if cmd == ‘q‘:break ret = Popen(cmd,shell=True, stdout=PIPE, stderr=PIPE) ck.send(ret.stdout.read()) ck.send(ret.stderr.read()) ck.close()
C/S远程命令
原文地址:https://www.cnblogs.com/guge-94/p/10729463.html
时间: 2024-09-29 12:57:37