Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. # Author: Charles Wood
  2. # ========================
  3. # Prerequisites
  4. #
  5. # Visual C++ Build Tools 2015 (for SSH): http://landinghub.visualstudio.com/visual-cpp-build-tools
  6. # paramiko - easy-install paramiko
  7.  
  8.  
  9. import sys
  10. import paramiko
  11. from contextlib import redirect_stdout
  12. import time
  13.  
  14. ip = input('Host IP:')
  15. username = input('Username:')
  16. password = input('Password:')
  17. sleep_time = 1
  18. ssh = paramiko.SSHClient()
  19.  
  20.  
  21. def main():
  22.  
  23. if __name__ == '__main__':
  24. def login(username, password, host, i):
  25. print("Trying connection as: ", username)
  26.  
  27. try:
  28.  
  29. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  30. ssh.connect(host, username=username, password=password)
  31. print("Connected to %s" % host)
  32. run_commands()
  33.  
  34. except paramiko.AuthenticationException:
  35. print("Authentication failed when connecting to %s" % host)
  36. sys.exit(1)
  37.  
  38. def run_commands():
  39.  
  40. time_string = time.strftime("%Y%m%d-%H%M%S")
  41. (stdin, stdout, stderr) = ssh.exec_command('ifconfig', get_pty=True)
  42. type(stdin)
  43. with open('PDU Log_'+time_string, 'w') as f:
  44. with redirect_stdout(f):
  45. for output in stdout:
  46. print(output)
  47.  
  48. login(username, password, ip, sleep_time)
  49. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement