import socket
import subprocess
import os
server = socket.socket()
server.bind(
('127.0.0.1',8888)
)
server.listen(3)
while 1:
conn ,addr = server.accept()
print(addr)
while 1 :
try:
data = conn.recv(1024).decode('utf8')
if data == 'q':
break
if len(data) == 0:
continue
print(data)
# conn.send(data.encode('utf8'))
# res = subprocess.Popen(data,shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
data=subprocess.Popen(data)
# stdout = subprocess.PIPE
out = data.stdout
conn.send(out.encode('utf8'))
# os.system(data)
except Exception as e:
print(e)
break
conn.close()
````````````````````````````````````````````````````````````````````````````
import socket
client = socket.socket()
client.connect(
('127.0.0.1', 8888)
)
while 1 :
cmd_msg = input('cmd:')
if cmd_msg == 'q':
break
client.send(cmd_msg.encode('utf8'))
data = client.recv(1024).decode('utf8')
print(data)
client.close()