Skip to main content

This Package Will Parse Cisco IOS, IOS-XE and IOS-XR Configuration File.

Project description

Cisco Configuration Parser

This Package Will Parse Cisco IOS, IOS-XE and IOS-XR Configuration File.

There are two ways to parse the config, 1, SSH which is not recommended, and 2, feeding the running-config file

  • to use file, use ConfigParser(file=your_file).
  • to use SSH:
ConfigParser(
    ssh=True, 
    user="username", 
    password="password", 
    device_type="cisco_ios", 
    host="your_switch_ip"
    )

device types that are accepted are:

cisco_ios
cisco_xe
cisco_xr

pass the kwargs then it will login to your device and does the show running-config and will parse it.

Install the package

https://pypi.org/project/cisco-config-parser/

pip install cisco-config-parser

Regex Search Strings:

  • to find lines in the configuration starting with "router"
parse.find_parent_child("^router")
  • to parse all confuguration into parent and child format
parse.find_parent_child("^.")
  • to find lines in the configuration that has "Loopback" in them
parse.find_parent_child("^.*Loopback")

Examples:

  • Getting Routed Ports
from cisco_config_parser import ConfigParser

file = "running-config.txt"

parser = ConfigParser(file=file)

obj = parser.get_routed_port()

for i in obj:
    print(i.intf)
    print(i.ip_add, i.mask)
    print(i.subnet)
    print(i.description)
    print(i.vrf)
    print(i.description)
    print(i.state)
    print("!")

output:

interface TenGigE0/3/0/29.3240
10.10.1.1 255.255.255.248
10.10.1.0/29
 description Connected to device_A
 vrf vrf_A
 no shutdown
!
interface TenGigE0/3/0/29.3340
10.244.10.1 255.255.255.252
10.244.10.0/30
 description Connected to device_A
 vrf vrf_B
 no shutdown
  • Getting Switchport:
from cisco_config_parser import ConfigParser

file = "switch01_run_config.txt"

parser = ConfigParser(file=file)

obj = parser.get_switchport()

for i in obj:
    print(i.port)
    print(i.mode)
    print(i.vlan)
    print(i.voice)
    print(i.description)
    print("!")

output:

  
interface GigabitEthernet10/38
Access Port
Vlan  200
Voice  vlan 700
 description ent-user
!
interface GigabitEthernet10/38
Access Port
Vlan  200
Voice  vlan 700
 description ent-user
  • Finding Routing Protocol
    from cisco_config_parser import ConfigParser
    
    
    my_file = "switch01_running_config.txt"
    parse = ConfigParser(file=my_file)
    
    
    obj_list = parse.find_parent_child("^router")
    for i in obj_list:
        print(i.parent)
        for child_obj in i.child:
            print(child_obj)
 

Output:

router eigrp 252
!
address-family ipv4 vrf vrf_A autonomous-system 252
 network 10.10.10.0 0.0.0.63
 passive-interface default
 no passive-interface Vlan3123
 no passive-interface Vlan3124
 eigrp stub connected summary
exit-address-family
!
address-family ipv4 vrf vrf_B autonomous-system 252
 network 10.20.10.0 0.0.0.3
 network 10.20.11.0 0.0.0.3
 passive-interface default
 no passive-interface Vlan3223
 no passive-interface Vlan3224
 eigrp stub connected summary
exit-address-family
!

  • Finding Interface and Helper address Example
    from cisco_config_parser import ConfigParser


    my_file = "switch01_running_config.txt"
    parse = ConfigParser(file=my_file)
    obj_list = parse.find_parent_child("^interface")

    for i in obj_list:
        vlan_200 = re.search("Vlan200", i.parent)
        if vlan_200:
            print(i.parent)
            for c_obj in i.child:
                if str(c_obj).startswith(" ip helper"):
                    print(str(c_obj))

Output:

interface Vlan200
 ip helper-address 192.168.1.10
 ip helper-address 172.31.10.10
  • Finding SVI in the config with all its child configuration
from cisco_config_parser import ConfigParser



file = "switch_01-run_config.txt"
parser = ConfigParser(file=file)

res = parser.get_svi_objects()

for i in res:
    if "lan200" in i.intf:
        print(i.intf)
        print(i.ip_add)
        print(i.description)
        print(i.vrf)
        print(i.state)
        print(i.helper)
        print("!")

output:

interface Vlan200
 ip address 10.20.80.1 255.255.254.0
 description USER VLAN-
 ip vrf forwarding vrf_A
 no shutdown
[' ip helper-address 10.10.1.10 ', ' ip helper-address 10.20.1.10']
!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cisco_config_parser-1.2.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

cisco_config_parser-1.2.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file cisco_config_parser-1.2.1.tar.gz.

File metadata

  • Download URL: cisco_config_parser-1.2.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cisco_config_parser-1.2.1.tar.gz
Algorithm Hash digest
SHA256 b57fb9707fb599113a07169c13c426722846528d51fce126365bda878f02ffaa
MD5 39261747a4761c49c5fce2f8915f13bb
BLAKE2b-256 24283ce64c0d90cb21b9210e3d68f3b66c27c7f6d01210c498a638ecf7033d5b

See more details on using hashes here.

File details

Details for the file cisco_config_parser-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: cisco_config_parser-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.5

File hashes

Hashes for cisco_config_parser-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6db09f90bc98bc818d49866282da789b2679c03a0a5b5d8ef42148450a4faa8a
MD5 607a7c33f552ed661fdab9cc48a129f6
BLAKE2b-256 075251c144c3e8da745173106f09b4e459d84c8b90f6670ce18ad7dc9c156c39

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page