pip install netmiko
from netmiko import ConnectHandler
# Define the device to connect to
cisco_device = {
'device_type': 'cisco_ios', # This should be the correct device type (e.g.,
'cisco_ios' for IOS devices)
'host': '192.168.1.1', # Replace with your device's IP address
'username': 'your_username', # Replace with your username
'password': 'your_password', # Replace with your password
'secret': 'your_enable_secret', # Replace with your enable password (if needed)
}
# Establish an SSH connection to the device
net_connect = ConnectHandler(**cisco_device)
# Enter enable mode (if necessary)
net_connect.enable()
# List of show commands to run
commands = [
'show version',
'show ip interface brief',
'show running-config',
# Add more show commands as needed
]
# Dictionary to store command outputs
output = {}
# Execute each command and store the output
for command in commands:
output[command] = net_connect.send_command(command)
# Print the output of each command
for command, result in output.items():
print(f"Command: {command}\n")
print(result)
print("\n" + "="*80 + "\n")
# Disconnect from the device
net_connect.disconnect()