模拟远程执行ssh服务端

from socket import *
import subprocess
server=socket(AF_INET,SOCK_STREAM)
server.bind(('127.2.2.2',6688))
server.listen(5)
while True:
    conn,client_addr=server.accept()
    print(client_addr)
    while True:
        try:
           cmd=conn.recv(1024)
           if not cmd:break
           obj=subprocess.Popen(cmd.decode('utf-8'),shell=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE
                                )
           stdout=obj.stdout.read()
           stderr=obj.stderr.read()
           cmd_res=stdout+stderr
           print(len(cmd_res))
           conn.send(cmd_res)
        except ConnectionResetError:break
    conn.close()
server.close()
上一篇:9、Android---UI---Material Design


下一篇:系统相关的信息模块——sys