Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import sys, paramiko, getpass
  2.  
  3.  
  4. user = input("Username:") #Prompts for username
  5. #passwd = getpass.getpass("Password for " + user + ":") #Prompts for password
  6. key_file = input("Public key full path:") #Prompts for full path to key file
  7. name = input("Target Hostname:") #Prompt for target hostname
  8. command = input("Enter target command:") #Prompt for remote command
  9.  
  10.  
  11. #Calling the paramiko ssh function
  12. ssh = paramiko.SSHClient() #Define value 'ssh' as calling the paramiko.sshclient
  13. print('calling paramiko')
  14. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #Must come before connect line to add hosts to known_hosts
  15. #ssh.connect("name", username="user", password="passwd")
  16. ssh.connect(hostname = name, username = user, key_filename = key_file) # key_filename means to specify the actual file, pkey on the
  17. #other hand means to actually paste in the key text itself
  18. print('trying to connect')
  19. ssh.invoke_shell()
  20. stdin, stdout, stderr = ssh.exec_command (command)
  21. print(stdout.read())
  22. #ssh.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement