Guest User

Untitled

a guest
May 24th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. def shell(chan):
  2. import select
  3.  
  4. oldtty = termios.tcgetattr(sys.stdin)
  5. try:
  6. tty.setraw(sys.stdin.fileno())
  7. tty.setcbreak(sys.stdin.fileno())
  8. chan.settimeout(0.0)
  9.  
  10. while True:
  11. r, w, e = select.select([chan, sys.stdin], [], [])
  12. if chan in r:
  13. try:
  14. x = chan.recv(1024)
  15. print 'if len(x) == 0:'
  16. if len(x) == 0:
  17. print '\r\n*** EOF\r\n',
  18. break
  19. sys.stdout.write(x)
  20. sys.stdout.flush()
  21. except socket.timeout:
  22. print 'pass'
  23. pass
  24. if sys.stdin in r:
  25. x = sys.stdin.read(1)
  26. if len(x) == 0:
  27. print 'break'
  28. break
  29. chan.send(x)
  30.  
  31. finally:
  32. termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)
  33.  
  34. if __name__ == '__main__':
  35. paramiko.util.log_to_file('psshc-interactive_shell.log')
  36. trn = paramiko.Transport((hostname,port))
  37. trn.connect(username=username, password=password)
  38. chn = trn.open_channel(kind='direct-tcpip', dest_addr=('h1m',22), src_addr=('hm',22))
  39. shell(chn)
  40. chn. close()
Add Comment
Please, Sign In to add comment