Package: cisco-config-parser
Cisco Configuration ParserThis Package Will Parse Cisco IOS, IOS-XE, IOS-XR, and NXOS Configuration File.There are two ways to parse the config, 1, SSH which is not recommended, and 2, feeding the running-config fileto use file, useConfigParser(method="file", content=<your_file>).to use SSH:ConfigParser(method="int_ssh",ssh=True,user="username",password="password",device_type="cisco_ios",host="your_switch_ip")device types that are accepted are:cisco_ioscisco_xecisco_xrcisco_nxospass the kwargs then it will login to your device and does theshow running-configand will parse it.Install the packagehttps://pypi.org/project/cisco-config-parser/pipinstallcisco-config-parserRegex Search Strings:to find lines in the configuration starting with "router"parse.find_parent_child("^router")to parse all confuguration into parent and child formatparse.find_parent_child("^.")to find lines in the configuration that has "Loopback" in themparse.find_parent_child("^.*Loopback")Examples:Parsing NXOS Config For All the Related VLAN Info.>>>nxos_parser=ConfigParser(method="file",content=file1)>>>vlan_info=nxos_parser.nxos_get_vlan_info()>>>vlan_info.vlan="2626">>>print(vlan_info.vlan):return:!vlan2626nameGRN200_nonPROD_APP_01vn-segment2002626!interfaceVlan2626descriptiongrn200nonPRODAppServers01noshutdownmtu9216vrfmemberGRN200noipredirectsipaddress10.147.148.1/24noipv6redirectsfabricforwardingmodeanycast-gateway!intnve1membervni2002626suppress-arpingress-replicationprotocolbgp!evpnvni2002626l2rdautoroute-targetimportautoroute-targetexportautGetting Routed Portsfromcisco_config_parserimportConfigParsermy_file="running-config.txt"parser=ConfigParser(method="file",content=my_file)obj=parser.ios_get_routed_port()foriinobj: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 shutdownGetting Switchport:
there are two different mode on switchport,accessandtrunk. you should specify the modemode=trunkormode=access. this way you will be able to access all the access-ports or trunk-ports by accessing the methods (get_access or get_trunk)fromcisco_config_parserimportConfigParsermy_file="switch01_run_config.txt"parser=ConfigParser(method="file",content=my_file)obj=parser.ios_get_switchport(mode="access")foriinobj:print(i.port)print(i.vlan)print(i.voice)print(i.description)print("!")foriinobj:print(i.get_access)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-userFinding Routing Protocolfromcisco_config_parserimportConfigParsermy_file="switch01_running_config.txt"parse=ConfigParser(method="file",content=my_file)obj_list=parse.find_parent_child("^router")foriinobj_list:print(i.parent)forchild_objini.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 Examplefromcisco_config_parserimportConfigParsermy_file="switch01_running_config.txt"parse=ConfigParser(method="file",content=my_file)obj_list=parse.find_parent_child("^interface")foriinobj_list:vlan_200=re.search("Vlan200",i.parent)ifvlan_200:print(i.parent)forc_objini.child:ifstr(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.10Finding SVI in the config with all its child configurationfromcisco_config_parserimportConfigParsermy_file="switch_01-run_config.txt"parser=ConfigParser(method="file",content=my_file)res=parser.ios_get_svi_objects()foriinres:if"lan200"ini.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']
!