ciscoconfparse

1.9.52 · deprecated · verified Thu Apr 16

ciscoconfparse is a Python library designed for parsing, auditing, querying, building, and modifying Cisco IOS-style configurations. It also supports other vendor configurations that follow a similar hierarchical structure. The current version is 1.9.52, but it is considered End of Life, with all new development moving to its successor, `ciscoconfparse2`.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `CiscoConfParse` with a list of configuration lines and then use `find_parent_objects` to locate shutdown interfaces and `find_objects_w_child` to find interfaces with IP addresses. The library supports searching using regular expressions.

from ciscoconfparse import CiscoConfParse

# Example Cisco configuration lines
config_text = [
    'hostname Router1',
    '!',
    'interface GigabitEthernet0/1',
    ' description Uplink to Core',
    ' ip address 192.168.1.1 255.255.255.0',
    ' no shutdown',
    '!',
    'interface GigabitEthernet0/2',
    ' description Access Port',
    ' switchport mode access',
    ' switchport access vlan 10',
    ' shutdown',
    '!',
    'router bgp 65000',
    '  neighbor 10.0.0.1 remote-as 65001'
]

# Create a CiscoConfParse object from a list of configuration lines
parse = CiscoConfParse(config_text)

# Find all interfaces that are administratively shutdown
shutdown_interfaces = parse.find_parent_objects('^interface', 'shutdown')

if shutdown_interfaces:
    print('Shutdown Interfaces:')
    for intf in shutdown_interfaces:
        # intf.text gives the parent line (e.g., 'interface GigabitEthernet0/2')
        print(f'- {intf.text}')
else:
    print('No shutdown interfaces found.')

# Find all interfaces with an IP address
interfaces_with_ip = parse.find_objects_w_child(parentspec='^interface', childspec='ip address')

if interfaces_with_ip:
    print('\nInterfaces with IP addresses:')
    for intf in interfaces_with_ip:
        ip_line = intf.re_search_children(r'ip address (\S+ \S+)', result_type=str, group=1)
        if ip_line:
            print(f'- {intf.text}: {ip_line}')

view raw JSON →