Advertisement
Guest User

Untitled

a guest
Oct 4th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import threading
  2. import paramiko
  3. import subprocess
  4.  
  5. def ssh_command(ip, user, passwd, command):
  6. client = paramiko.SSHClient()
  7. # client.load_host_keys('/home/justin/.ssh/known_hosts')
  8. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  9. client.connect(ip, username=user, password=passwd)
  10. ssh_session = client.get_transport().open_session()
  11. if ssh_session.active:
  12. ssh_session.send(command)
  13. print(ssh_session.recv(1024).decode()) # read banner
  14. while True:
  15. command = input("$ ").strip('\n')
  16. try:
  17. ssh_session.send(command) # c
  18. print(str(ssh_session.recv(1024).decode())) # get output
  19. except Exception as e:
  20. print(type(e))
  21. client.close()
  22. return
  23.  
  24. ssh_command('localhost', 'justin', 'lovesthepython','ClientConnected')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement