Effortless Cisco Network Insights: Retrieving Configurations with Python and Netmiko

Effortless Cisco Network Insights: Retrieving Configurations with Python and Netmiko


In our ongoing exploration of network automation with Python and Netmiko, today’s focus is on extracting crucial configuration information from Cisco routers. The provided script empowers network administrators to effortlessly retrieve details like interface brief or system version, streamlining the monitoring and management of Cisco networks.

Script Breakdown:

The script begins by establishing a Telnet connection to a Cisco router using the Netmiko library. The router details, including device type, IP address, username, and passwords, are specified in a dictionary.

router = {
    'device_type': 'cisco_ios_telnet',
    'ip': '',
    'username': 'cisco',
    'password': 'cisco@123',
    'secret': 'cisco@123',

net_connect = None

    # Establish a Telnet connection to the router using Netmiko
    net_connect = ConnectHandler(**router)

    # Enter enable mode on the router

    # If successful, print a success message
    print("Telnet login successful!")

    # Execute 'show ip interface brief' command
    output = net_connect.send_command("show ip interface brief")

    # Print the command output
    print("\nOutput of 'show ip interface brief':\n")

except Exception as e:
    # If any exception occurs during the connection attempt or command execution, print an error message
    print(f"Error: {str(e)}")

    # Handle netconnection if router session is established
    if net_connect:
        # Disconnect from the router, regardless of success or failure


The script extends its capabilities by executing the ‘show ip interface brief’ command, providing a quick overview of the router’s interface status.



By integrating this script into your network automation toolkit, you can effortlessly gather essential configuration details from Cisco routers. Whether you need a snapshot of interface statuses or want to check the current system version, the power of Python and Netmiko simplifies these tasks, enhancing your network management efficiency. Stay tuned for more insights into network automation as we continue to explore ways to optimize and streamline your networking experience.


Here is the link to YouTube video:


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *