Advertisement
l31ank

Test_SSH_Script

Jun 9th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import subprocess , sys , paramiko , getpass
  2.  
  3.  
  4. hostName = ''
  5. userName = ''
  6. passWord = ''
  7. command = ""
  8. port = 22
  9.  
  10. if len(sys.argv) < 2:
  11.     hostName = raw_input('[+] Hostname : ')
  12.     userName = raw_input('[+] Username : ')
  13.     passWord = getpass.getpass('[+] Password : ')
  14. else:
  15.     hostName = sys.argv[1]
  16.     userName = sys.argv[2]
  17.     passWord = sys.argv[3]
  18.  
  19. try:
  20.     client = paramiko.SSHClient()
  21.     client.load_system_host_keys()
  22. ### Test Pair_Keys to Host ###
  23. #   print client.load_system_host_keys()
  24. ### Test Pair_Keys to Host ###
  25.     client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  26.     client.connect(hostName , port=port , username=userName ,
  27.         password=passWord)
  28.     print "command [exit] to end!!!!!"
  29.     while(command != 'exit'):
  30.         command = raw_input('@'+str(userName)+'# ')
  31.         stdin , stdout , stderr = client.exec_command(command)
  32.         print stdin
  33.         if stdout == '':
  34.             err = stderr.readlines()
  35.             print >>sys.stderr, "ERROR: %s" % err
  36.  
  37.         else:
  38.             for line in stdout:
  39.                 print('[+]' + line.strip('\n'))
  40.  
  41. except Exception, e:
  42.     print e
  43. finally:
  44.     client.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement