示例#1
0
def crypt():

    file = raw_input("\nName of file?\n")
    cfg = ccp(file)

    cry_ent = cfg.find_objects(r"crypto map CRYPTO")
    for items in cry_ent:
        print(items.text)
        for child in items.children:
            print(child).text
示例#2
0
def noaes():

    file=open(raw_input("\nFile Name?\n"))

    cfg=ccp(file)

    nosecure=cfg.find_objects_wo_child(parentspec=r"crypto map CRYPTO",childspec=r"set transform-set AES")
    for entry in nosecure:
        print(entry.text)
        for line in entry.children:
            print(line.text)
示例#3
0
def pfs():


    file=raw_input("\nFile Name?\n")
    cfg=ccp(file)

    crypt=cfg.find_objects_w_child(parentspec=r"crypto map",childspec=r"set pfs group2")
    for entry in crypt:
        print(entry.text)
        for line in entry.children:
            print(line.text)
示例#4
0
#!/usr/bin/env python

import sys
import re
from ciscoconfparse import CiscoConfParse as ccp
import yaml

conf=ccp("cisco_ipsec.txt")

# create ifconfigs list (list of dictionaries)
ifconfigs=[]
for interf in conf.find_objects("interface"):
  newdict={}
  newdict[interf.text]=[]
  for child in interf.children:
    newdict[interf.text].append(child.text)
  ifconfigs.append(newdict)
print "ifconfigs=%s" %ifconfigs

# show ifconfigs
for dict in ifconfigs:
  key=dict.keys()[0]
  print key
  for conf in dict[key]:
    print conf

# write to file
with open("yaml.yml","w") as f:
  f.write(yaml.dump(ifconfigs))

# read from file
示例#5
0
#!/usr/bin/env python

from ciscoconfparse import CiscoConfParse as ccp

cfg_obj = ccp('data/cisco_ipsec.txt')
pfs = cfg_obj.find_objects_w_child(parentspec='^crypto map CRYPTO',
                                   childspec='pfs group2')
print pfs
示例#6
0
#!/usr/bin/env python
"""
Find all of the crypto map entries that are using PFS group2
"""

from ciscoconfparse import CiscoConfParse as ccp

cisco_cfg = ccp("cisco.txt")

group2 = cisco_cfg.find_objects_w_child(parentspec=r"^crypto map",
                                        childspec=r"set pfs group2")

print "search group: set pfs group2\n"

for i in group2:
    print i.text
示例#7
0
    5    DDDDD                            active
    6    EEEEE                            active
    7    FFFFF                            active    Fa0/25, Fa0/26, Fa0/27, Fa0/28, Fa0/29, Fa0/30
    1002 fddi-default                     act/unsup
    1003 token-ring-default               act/unsup
    1004 fddinet-default                  act/unsup
    1005 trnet-default                    act/unsup
    
    To configuration like this .....
    vlan 2
     name AAAAA
    vlan 3
     name BBBBB
    vlan 4
     name CCCCC
    vlan 5
     name DDDDD
    vlan 6
     name EEEEE
    vlan 7
     name FFFFF
    """
    active_vlans = vlans.find_objects("active")
    for i in active_vlans:
        if not " ".join(i.text.split()[0:1]) == "1":
            print("vlan", " ".join(i.text.split()[0:1]))
            print(" name", " ".join(i.text.split()[1:2]))


extract_vlan(ccp("show_vlan.txt"))
示例#8
0
#!/usr/bin/env python

from ciscoconfparse import CiscoConfParse as ccp
from pprint import pprint as pp

with open("cisco_ipsec.txt") as f:
    my_cfg = ccp(f)

for obj in my_cfg.find_objects(r"crypto map CRYPTO"):
    pp("Object: " + str(obj) + " Val: " + str(obj.text))
    obj_child = obj.re_search_children(obj.text)
    for obj2 in obj_child:
        pp("Child: " + str(obj2))
示例#9
0
#!/usr/bin/env python
"""
8. Write a Python program using ciscoconfparse that parses this config file. 
Note, this config file is not fully valid (i.e. parts of the configuration are missing). 
The script should find all of the crypto map entries in the file (lines that begin with 'crypto map CRYPTO') 
and for each crypto map entry print out its children.
"""


from ciscoconfparse import CiscoConfParse as ccp
from pprint import pprint as pp

FILE = 'cisco_ipsec.txt'

# read cisco_ipsec.txt
cfg = ccp ( FILE )


cryptos = cfg.find_objects ( r'^crypto map ')

for c in cryptos:
    children = cfg.find_children ( c.text )

    for child in children:
        pp (child)