Advertisement
Guest User

Untitled

a guest
Feb 11th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import threading
  2.  
  3. import netmiko
  4. import getpass
  5.  
  6. # global variables
  7. _platform = 'juniper'
  8. _username = raw_input("Username?:")
  9. _password = getpass.getpass(prompt="Password?:")
  10. _port = 22
  11. _data = open("hosts.txt")
  12.  
  13.  
  14. def send_command(command, ip):
  15. try:
  16. dev_ssh = netmiko.ConnectHandler(
  17. device_type=_platform,
  18. ip=ip,
  19. username=_username,
  20. password=_password,
  21. port=_port,
  22. secret=_password,
  23. )
  24. output = dev_ssh.send_command(command).split()
  25.  
  26. with open(ip + ' configthreadmaybe.txt','w+') as file:
  27. for line in output:
  28. file.write(line)
  29.  
  30. print('{} -- Complete'.format(ip))
  31.  
  32. except:
  33. pass
  34.  
  35.  
  36. def main():
  37. all_devices = [ip for ip in _data]
  38. thread_list = [threading.Thread(target=send_command, args=('show interfaces descriptions',ip,)) for ip in all_devices]
  39.  
  40. for thread in thread_list:
  41. thread.start()
  42. for thread in thread_list:
  43. thread.join()
  44.  
  45. if __name__ == '__main__':
  46. main()
  47. print('Complete')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement