Created
February 26, 2026 16:23
-
-
Save abrand67/4d0344dac1a46c95536bba3a5f511674 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() | |
| command = "show version" | |
| # 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()) | |
| # cycle through each device sequentially and run the command | |
| for h in hosts: | |
| device = { | |
| "device_type": "arista_eos", | |
| "host": h, | |
| "username": uname, | |
| "password": pword, | |
| "session_log": h + ".log", | |
| } | |
| # Connect and send command | |
| with ConnectHandler(**device) as conn: | |
| output = conn.send_command(command, use_textfsm=True) | |
| for o in output: | |
| print(h + ' has an uptime of ' + o['uptime']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment