Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def shell(chan):
- import select
- oldtty = termios.tcgetattr(sys.stdin)
- try:
- tty.setraw(sys.stdin.fileno())
- tty.setcbreak(sys.stdin.fileno())
- chan.settimeout(0.0)
- while True:
- r, w, e = select.select([chan, sys.stdin], [], [])
- if chan in r:
- try:
- x = chan.recv(1024)
- print 'if len(x) == 0:'
- if len(x) == 0:
- print '\r\n*** EOF\r\n',
- break
- sys.stdout.write(x)
- sys.stdout.flush()
- except socket.timeout:
- print 'pass'
- pass
- if sys.stdin in r:
- x = sys.stdin.read(1)
- if len(x) == 0:
- print 'break'
- break
- chan.send(x)
- finally:
- termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
- if __name__ == '__main__':
- paramiko.util.log_to_file('psshc-interactive_shell.log')
- trn = paramiko.Transport((hostname,port))
- trn.connect(username=username, password=password)
- chn = trn.open_channel(kind='direct-tcpip', dest_addr=('h1m',22), src_addr=('hm',22))
- shell(chn)
- chn. close()
Add Comment
Please, Sign In to add comment