Skip to content

Instantly share code, notes, and snippets.

@abrand67
Created February 26, 2026 13:35
Show Gist options
  • Select an option

  • Save abrand67/b26c7aeb543688a495908f30557251c1 to your computer and use it in GitHub Desktop.

Select an option

Save abrand67/b26c7aeb543688a495908f30557251c1 to your computer and use it in GitHub Desktop.
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