Advertisement
Guest User

Untitled

a guest
Jan 18th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. __author__ = "ToddR"
  2. #
  3. #
  4. import paramiko
  5. import time
  6. import getpass
  7.  
  8. UN = raw_input("Username : ")
  9. PW = getpass.getpass("Password : ")
  10.  
  11. #
  12. #Create two text files "device_list.txt" and "cli_commands.txt"
  13. #
  14. device_list = []
  15. file1 = open('device_list.txt', 'r')
  16. for line in file1:
  17. device_list.append(line.strip())
  18. file1.close()
  19. print device_list
  20.  
  21. host_commands = []
  22. file2 = open('cli_commands.txt', 'r')
  23. for line in file2:
  24. host_commands.append(line.strip())
  25. file2.close()
  26. print host_commands
  27.  
  28. # For loop allows you to specify number of hosts
  29. for ip in device_list:
  30. print ip
  31. twrssh = paramiko.SSHClient()
  32. twrssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  33. twrssh.connect(ip, port=22, username=UN, password=PW)
  34. remote = twrssh.invoke_shell()
  35. remote.send('term len 0\n')
  36. remote.send('enable\n')
  37. remote.send('%s\n' % PW)
  38. time.sleep(1)
  39. #This for loop allows you to specify number of commands you want to enter
  40. #Dependent on the output of the commands you may want to tweak sleep time.
  41. for commands in host_commands:
  42. remote.send(' %s \n' % commands)
  43. time.sleep(1)
  44. buf = remote.recv(65000)
  45. print buf
  46. file3 = open('sshlogfile0001.txt', 'a')
  47. file3.write(buf)
  48. file3.close()
  49. twrssh.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement