How to use the ciscoconfparse.ccp_util.L4Object function in ciscoconfparse

To help you get started, we’ve selected a few ciscoconfparse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def testL4Object_asa_lt01():
    pp = L4Object(protocol='tcp', port_spec='lt echo', syntax='asa')
    assert pp.protocol=='tcp'
    assert pp.port_list==range(1, 7)
github mpenning / ciscoconfparse / tests / test_Models_Asa.py View on Github external
def testVal_object_group_service_02():
    ## This can only be configured as an object group after a host / network
    conf = ['!',
        'object-group service APP02_svc tcp',
        ' port-object eq smtp',
        ' port-object eq https',
        ' port-object range 8080 8081',
        '!',]
    cfg_factory = CiscoConfParse(conf, factory=True, syntax='asa')
    obj = cfg_factory.find_objects(r'object-group\sservice')[0]
    result_correct = [L4Object(protocol='tcp', port_spec='eq 25', 
        syntax='asa'), L4Object(protocol='tcp', port_spec='eq 443', 
        syntax='asa'), L4Object(protocol='tcp', port_spec='range 8080 8081',
        syntax='asa')]
    assert (obj.name=='APP02_svc')
    assert (obj.ports==result_correct)
    assert (obj.L4Objects_are_directional is False)
    assert (obj.protocol_type=='tcp')
github mpenning / ciscoconfparse / tests / test_Models_Asa.py View on Github external
def testVal_object_group_service_01():
    ## This can only be configured as protocol object-group
    conf = ['!',
        'object-group service APP01_svc',
        ' service-object tcp destination smtp',
        ' service-object tcp destination https',
        '!',]
    cfg_factory = CiscoConfParse(conf, factory=True, syntax='asa')
    obj = cfg_factory.find_objects(r'object-group\sservice')[0]
    result_correct = [L4Object(protocol='tcp', port_spec='eq 25', 
        syntax='asa'), L4Object(protocol='tcp', port_spec='eq 443', 
        syntax='asa')]
    assert (obj.name=='APP01_svc')
    assert (obj.ports==result_correct)
    assert (obj.L4Objects_are_directional is True)
    assert (obj.protocol_type=='')
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def testL4Object_asa_lt02():
    pp = L4Object(protocol='tcp', port_spec='lt 7', syntax='asa')
    assert pp.protocol=='tcp'
    assert pp.port_list==range(1, 7)
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def testL4Object_asa_range01():
    pp = L4Object(protocol='tcp', port_spec='range smtp 32', syntax='asa')
    assert pp.protocol=='tcp'
    assert pp.port_list==range(25, 33)
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def testL4Object_asa_eq01():
    pp = L4Object(protocol='tcp', port_spec='eq smtp', syntax='asa')
    assert pp.protocol=='tcp'
    assert pp.port_list==[25]
github mpenning / ciscoconfparse / tests / test_Models_Asa.py View on Github external
def testVal_object_group_service_03():
    ## This can only be configured as an object group after a host / network
    conf = ['!',
        'object-group service APP03_svc tcp-udp',
        ' port-object eq domain',
        '!',]
    cfg_factory = CiscoConfParse(conf, factory=True, syntax='asa')
    obj = cfg_factory.find_objects(r'object-group\sservice')[0]
    ## Test whether the proper port objects are returned
    results_correct = [L4Object(port_spec='eq 53', protocol='tcp', 
        syntax='asa'), 
        L4Object(port_spec='eq 53', protocol='udp', syntax='asa')]
    assert (obj.name=='APP03_svc')
    assert (obj.ports==results_correct)
    assert (obj.L4Objects_are_directional is False)
    assert (obj.protocol_type=='tcp-udp')
github mpenning / ciscoconfparse / tests / test_Ccp_Util.py View on Github external
def testL4Object_asa_eq02():
    pp = L4Object(protocol='tcp', port_spec='smtp', syntax='asa')
    assert pp.protocol=='tcp'
    assert pp.port_list==[25]
github mpenning / ciscoconfparse / ciscoconfparse / models_asa.py View on Github external
svc_obj = mm.groupdict()
            else:
                svc_obj = dict()

            if svc_obj.get('protocol', None):
                protocol = svc_obj.get('protocol')
                src_dst = svc_obj.get('src_dst', '')
                port = svc_obj.get('s_port', '')

                if protocol=='tcp-udp':
                    retval.append(L4Object(protocol='tcp', 
                        port_spec=port, syntax='asa'))
                    retval.append(L4Object(protocol='udp', 
                        port_spec=port, syntax='asa'))
                else:
                    retval.append(L4Object(protocol=protocol, 
                        port_spec=port, syntax='asa'))

            elif svc_obj.get('operator', None):
                op = svc_obj.get('operator', '')
                port = svc_obj.get('p_port', '')
                port_spec="{0} {1}".format(op, port)

                if self.protocol_type=='tcp-udp':
                    retval.append(L4Object(protocol='tcp', 
                        port_spec=port_spec, syntax='asa'))
                    retval.append(L4Object(protocol='udp', 
                        port_spec=port_spec, syntax='asa'))
                else:
                    retval.append(L4Object(protocol=self.protocol_type, 
                        port_spec=port_spec, syntax='asa'))