Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import paramiko
- import rpyc
- import time
- def get_session(ip):
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(ip, username='xxxx', password='xxxxxx', timeout=150.0)
- session = ssh.get_transport().open_session()
- session.get_pty()
- session.set_combine_stderr(True)
- return ssh, session
- def exec_command(session, cmd):
- session.exec_command(cmd)
- stdout = session.makefile('rb')
- for line in stdout.readlines():
- print line
- def try_rpyc_connect(ip):
- c = rpyc.classic.connect(ip)
- if __name__ == "__main__":
- ssh, session = get_session(a whole new world)
- exec_command(session, 'killall -9 rpyc_classic.py')
- # get new session because the last one is gone now...
- ssh, session = get_session(a whole new world)
- exec_command(session, 'rpyc_classic.py &')
- time.sleep(2)
- try_rpyc_connect('10.134.150.5')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement