Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from netmiko import ConnectHandler
- import sys
- import time
- import getpass
- #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
- #list all devices you'd like the config applying to in hosts.txt in the same folder as this python file.
- platform = 'cisco_ios'
- username = raw_input("Username? :")
- password = getpass.getpass(prompt="Password?: ")
- port = 22
- data = open("hosts.txt")
- for line in data:
- try:
- device = ConnectHandler(device_type=platform, ip=line.strip(), username=username, password=password, port=port, secret=password)
- device.enable()
- device_commands = [ 'ntp server 1.1.1.1',
- 'ntp server 2.2.2.2',
- 'end',
- 'wr mem']
- output = device.send_config_set(device_commands)
- print line
- print output
- f = open("configoutput.txt", 'a')
- f.write(str(line + output + "\n"))
- except:
- continue # Basically, ignore the error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement