def _open_interactive_shell(chan):
''' Opens a remote terminal interface
Note: Works only on unix as it uses POSIX style tty control
'''
oldtty = termios.tcgetattr(sys.stdin)
try:
tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno())
chan.settimeout(0.0)
while True:
r, dummy_w, dummy_e = select.select([chan, sys.stdin], [], [])
if chan in r:
try:
x = u(chan.recv(1024))
if len(x) == 0:
sys.stdout.write(
'\r\n*** Terminating the remote shell.\r\n')
break
sys.stdout.write(x)
sys.stdout.flush()
except socket.timeout:
pass
if sys.stdin in r:
x = sys.stdin.read(1)
if len(x) == 0:
break
chan.send(x)
finally:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
remote_access.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录