Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import paramiko
- import subprocess
- def ssh_command(ip, user, passwd, command):
- client = paramiko.SSHClient()
- # client.load_host_keys('/home/justin/.ssh/known_hosts')
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(ip, username=user, password=passwd)
- ssh_session = client.get_transport().open_session()
- if ssh_session.active:
- ssh_session.send(command)
- print(ssh_session.recv(1024).decode()) # read banner
- while True:
- command = input("$ ").strip('\n')
- try:
- ssh_session.send(command) # c
- print(str(ssh_session.recv(1024).decode())) # get output
- except Exception as e:
- print(type(e))
- client.close()
- return
- ssh_command('localhost', 'justin', 'lovesthepython','ClientConnected')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement