Advertisement
Guest User

Untitled

a guest
Sep 8th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import paramiko
  2. import rpyc
  3. import time
  4.  
  5.  
  6. def get_session(ip):
  7. ssh = paramiko.SSHClient()
  8. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  9. ssh.connect(ip, username='xxxx', password='xxxxxx', timeout=150.0)
  10.  
  11. session = ssh.get_transport().open_session()
  12. session.get_pty()
  13. session.set_combine_stderr(True)
  14.  
  15. return ssh, session
  16.  
  17. def exec_command(session, cmd):
  18. session.exec_command(cmd)
  19. stdout = session.makefile('rb')
  20.  
  21. for line in stdout.readlines():
  22. print line
  23.  
  24. def try_rpyc_connect(ip):
  25. c = rpyc.classic.connect(ip)
  26.  
  27. if __name__ == "__main__":
  28. ssh, session = get_session(a whole new world)
  29. exec_command(session, 'killall -9 rpyc_classic.py')
  30. # get new session because the last one is gone now...
  31. ssh, session = get_session(a whole new world)
  32. exec_command(session, 'rpyc_classic.py &')
  33. time.sleep(2)
  34. try_rpyc_connect('10.134.150.5')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement