客户端
import socket as fuck
Addr=('你的服务端ip',你服务端监听的端口)
fucker = fuck.socket(fuck.AF_INET,fuck.SOCK_STREAM)
fucker.connect(Addr)
while True:
text = input()
if not text:
print('not have')
break
fucker.send(text.encode())
recive= fucker.recv(1024)
if not recive:
break
print(recive.decode())
fucker.close()
服务端
import socket as fuck
import subprocess
import time
Addr=('',你监听的端口)
fucker = fuck.socket(fuck.AF_INET,fuck.SOCK_STREAM)
fucker.bind(Addr)
fucker.listen(5)
while True:
sock,addr = fucker.accept()
print('come from:',addr)
while True:
recive= sock.recv(1024)
if not recive:
break
cmd = subprocess.Popen(recive,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
data = cmd.stdout.read()
print(data)
sock.send(data.encode())
fucker.close()