socket-SSH模拟-server

#!/usr/bin/env python

import commands

import time

import SocketServer

class MyTCPHandler(SocketServer.BaseRequestHandler):

 

  def handle(self):

    print 'Got anew connection from',self.client_address

    while True:

      cmd  = self.request.recv(1024).strip()

      if not cmd:

        print 'Lostconnection with',self.client_address

        break

      print'recv:',cmd

      #print"{}wrote:".format(self.client_address[0])

      #printself.data

      cmd_result =commands.getstatusoutput(cmd)

      #send resultsize

     self.request.send(str(len(cmd_result[1])))

     time.sleep(0.2)

      #send result

     self.request.send(cmd_result[1])

 

 

if __name__ == "__main__":

 HOST,PORT="192.168.2.110",90

  server =SocketServer.ThreadingTCPServer((HOST,PORT),MyTCPHandler)

  server.serve_forever()

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS