Created
February 26, 2026 13:35
-
-
Save abrand67/b26c7aeb543688a495908f30557251c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from getpass import getpass | |
| from netmiko import ConnectHandler | |
| # Prompt for device credentials | |
| uname = input('Username: ') | |
| pword = getpass() | |
| # collect devices that will be configured | |
| hosts = [] # create list object | |
| with open('hosts.txt', 'r') as hFile: | |
| for line in hFile: | |
| hosts.append(line.strip()) | |
| # collect the commands that will be run against those devices | |
| commands = [] # create list object | |
| with open('commands.txt', 'r') as cFile: | |
| for line in cFile: | |
| commands.append(line.strip()) | |
| # cycle through each device sequentially and run the commands | |
| for h in hosts: | |
| device = { | |
| "device_type": "cisco_ios", | |
| "host": h, | |
| "username": uname, | |
| "password": pword, | |
| "session_log": h + ".log", | |
| } | |
| # Connect and send config | |
| with ConnectHandler(**device) as conn: | |
| for c in commands: | |
| conn.send_command(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment