Advertisement
Guest User

Untitled

a guest
Feb 1st, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import os
  2. from netmiko import ConnectHandler
  3. import sys
  4. import time
  5. import getpass
  6.  
  7. #config goes in device_commands - conf t happens by default - put in each line whatever config needs applying - I've put in a basic example for ntp
  8.  
  9. #list all devices you'd like the config applying to in hosts.txt in the same folder as this python file.
  10.  
  11. platform = 'cisco_ios'
  12. username = raw_input("Username? :")
  13. password = getpass.getpass(prompt="Password?: ")
  14. port = 22
  15. data = open("hosts.txt")
  16. for line in data:
  17. try:
  18. device = ConnectHandler(device_type=platform, ip=line.strip(), username=username, password=password, port=port, secret=password)
  19. device.enable()
  20. device_commands = [ 'ntp server 1.1.1.1',
  21. 'ntp server 2.2.2.2',
  22. 'end',
  23. 'wr mem']
  24. output = device.send_config_set(device_commands)
  25. print line
  26. print output
  27. f = open("configoutput.txt", 'a')
  28. f.write(str(line + output + "\n"))
  29. except:
  30. continue # Basically, ignore the error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement