-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciscoconfigparse
59 lines (34 loc) · 1.29 KB
/
ciscoconfigparse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
http://www.pennington.net/py/ciscoconfparse/tutorial.html
Cisco ConfParse:
pip install ciscoconfparse
from ciscoconfparse import CiscoConfParse
cisco_cfg = CiscoConfParse("cisco_config.txt")
interfaces = cisco_cfg.find_objects(r"^interface")
for i in interfaces:
print i.text
fa4 = interface[4]
# To see the children underneath an element:
print fa4.children
# To see it more human readable:
for child in fa4.child:
print child.text
# Child is just one level of indentation. To see all levels of indentation:
crypto_pki = cisco_cfg.find_objects(r"crypto pki certificate")
# this grabs just the first element in the list
crypto_pki = crypto_pki[0]
crypto_pki.all_children
# this will print all the children
for child in crypto_pki.all_children:
print child.text
# to check if something is a child:
<variable>.child
# to check if something is a parent:
<variable>.parent
# to see the parent of a child
<variable>.parent
# to see all parents
<variable>.all_parents
# for find objects with child underneath interface and has value "no ip address"
cisco_cfg.find_objects_w_child(parentspec=r"^interface, childspec=r"no ip address")
# for find objects without child finds everything that doesnt match the child spec
cisco_cfg.find_objects_wo_child(parentspec=r"^interface, childspec=r"no ip address")