0% found this document useful (0 votes)
1 views1 page

Python Program for Collecting Logs

This document provides a Python script using the Netmiko library to connect to a Cisco IOS device via SSH. It defines the device's connection parameters, executes several show commands, and prints the output. Finally, it disconnects from the device after executing the commands.

Uploaded by

mohsin.risk93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views1 page

Python Program for Collecting Logs

This document provides a Python script using the Netmiko library to connect to a Cisco IOS device via SSH. It defines the device's connection parameters, executes several show commands, and prints the output. Finally, it disconnects from the device after executing the commands.

Uploaded by

mohsin.risk93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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()

You might also like