socket-SSH模拟-client

#!/usr/bin/env python

import socket

import sys

 

HOST,PORT="192.168.2.110",90

sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

sock.connect((HOST,PORT))

 

def recv_all(obj,msg_length):

  raw_result = ''

  while True:

    if msg_length<=4096:

      data =obj.recv(msg_length)

      raw_result +=data

      break

    else:

      data =obj.recv(4096)

      raw_result+=data

      msg_length-=4096

  return raw_result

 

 

while True:

  data =raw_input('msg to send::').strip()

  if len(data) ==0:continue

 sock.sendall(data+"\n")

  res_size =int(sock.recv(1024))

  print 'data sizefrom server',res_size

  result =recv_all(sock,res_size)

  print result

 

sock.close()

 

分割线
打赏
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS