Parsing Running Configs

https://pypi.org/project/ciscoconfparse/

Example 1:
from ciscoconfparse import CiscoConfParse
parse = CiscoConfParse(‘voss1run.log’, syntax=’ios’)
for intf_obj in parse.find_objects(‘^interface GigabitEthernet’):
print(“Interfaces: ” + intf_obj.text)
Interfaces: interface GigabitEthernet 1/1
Interfaces: interface GigabitEthernet 1/8
Example 2:
from ciscoconfparse import CiscoConfParse
parse = CiscoConfParse(‘exampleswitch.conf’, sytax=’ios’)
global_obj = parse.find_objects(r’^prompt’)[0]
hostname = global_obj.re_match_typed(r’^prompt\s+(\S+)’, default=”)
hostname
‘”VOSS1″‘

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s