Advertisement
Guest User

Untitled

a guest
Dec 15th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. from netmiko import ConnectHandler
  2. from datetime import datetime
  3. import getpass
  4. import time
  5. import sys
  6.  
  7. print('CTRL-C to Exit Program at any time.')
  8. time.sleep(1)
  9.  
  10. username = input('Enter username for device login:')
  11.  
  12. def enterPassword():
  13. while True: # repeat forever
  14. password = getpass.getpass('Enter password:')
  15. password_again = getpass.getpass('Confirm password:')
  16. if password != password_again:
  17. print ('Passwords do not match. Please try again.')
  18. else:
  19. return password
  20. password = enterPassword()
  21.  
  22. run_command = input('Type command you would like to run:')
  23. if run_command == 'request':
  24. print('Request commands are not allowed. Exiting script')
  25. sys.exit()
  26. elif run_command == 'start':
  27. print('Start commands are not allowed. Exiting script')
  28. sys.exit()
  29. elif run_command == 'edit':
  30. print('Edit commands are not allowed. Exiting script')
  31. sys.exit()
  32. elif run_command == 'restart':
  33. print('Restart commands are not allowed. Exiting script')
  34. sys.exit()
  35.  
  36. device_type = 'juniper'
  37.  
  38. devices = ['mpr0-wrrnoh', 'mpr0-mrcrpa', 'as0-wrrnoh']
  39.  
  40. start_time = datetime.now()
  41.  
  42. for device in devices:
  43. net_connect = ConnectHandler(device_type = device_type, ip = device, username = username, password = password)
  44. output = net_connect.send_command(run_command)
  45. print("***", device, "***")
  46. print(output)
  47. print("*** END ***")
  48.  
  49. end_time = datetime.now()
  50. total_time = end_time - start_time
  51. print ('Total time to run script: ', total_time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement