當前位置: 首頁>>代碼示例>>Python>>正文


Python dadict.fixname方法代碼示例

本文整理匯總了Python中scapy.dadict.fixname方法的典型用法代碼示例。如果您正苦於以下問題:Python dadict.fixname方法的具體用法?Python dadict.fixname怎麽用?Python dadict.fixname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scapy.dadict的用法示例。


在下文中一共展示了dadict.fixname方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: mib_register

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def mib_register(ident, value, the_mib, unresolved):
    if ident in the_mib or ident in unresolved:
        return ident in the_mib
    resval = []
    not_resolved = 0
    for v in value:
        if _mib_re_integer.match(v):
            resval.append(v)
        else:
            v = fixname(v)
            if v not in the_mib:
                not_resolved = 1
            if v in the_mib:
                v = the_mib[v]
            elif v in unresolved:
                v = unresolved[v]
            if type(v) is list:
                resval += v
            else:
                resval.append(v)
    if not_resolved:
        unresolved[ident] = resval
        return False
    else:
        the_mib[ident] = resval
        keys = list(unresolved.keys())
        i = 0
        while i < len(keys):
            k = keys[i]
            if mib_register(k,unresolved[k], the_mib, {}):
                del(unresolved[k])
                del(keys[i])
                i = 0
            else:
                i += 1

        return True 
開發者ID:DinoTools,項目名稱:dionaea,代碼行數:39,代碼來源:mib.py

示例2: load_mib

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def load_mib(filenames):
    the_mib = {'iso': ['1']}
    unresolved = {}
    for k in list(conf.mib.keys()):
        mib_register(k, conf.mib[k].split("."), the_mib, unresolved)

    if type(filenames) is str:
        filenames = [filenames]
    for fnames in filenames:
        for fname in glob(fnames):
            f = open(fname)
            text = f.read()
            cleantext = " ".join(
                _mib_re_strings.split(" ".join(_mib_re_comments.split(text))))
            for m in _mib_re_oiddecl.finditer(cleantext):
                gr = m.groups()
                ident,oid = gr[0],gr[-1]
                ident=fixname(ident)
                oid = oid.split()
                for i in range(len(oid)):
                    m = _mib_re_both.match(oid[i])
                    if m:
                        oid[i] = m.groups()[1]
                mib_register(ident, oid, the_mib, unresolved)

    newmib = MIBDict(_name="MIB")
    for k,o in the_mib.items():
        newmib[k]=".".join(o)
    for k,o in unresolved.items():
        newmib[k]=".".join(o)

    conf.mib=newmib 
開發者ID:DinoTools,項目名稱:dionaea,代碼行數:34,代碼來源:mib.py

示例3: mib_register

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def mib_register(ident, value, the_mib, unresolved):
    if ident in the_mib or ident in unresolved:
        return ident in the_mib
    resval = []
    not_resolved = 0
    for v in value:
        if _mib_re_integer.match(v):
            resval.append(v)
        else:
            v = fixname(v)
            if v not in the_mib:
                not_resolved = 1
            if v in the_mib:
                v = the_mib[v]
            elif v in unresolved:
                v = unresolved[v]
            if type(v) is list:
                resval += v
            else:
                resval.append(v)
    if not_resolved:
        unresolved[ident] = resval
        return False
    else:
        the_mib[ident] = resval
        keys = unresolved.keys()
        i = 0
        while i < len(keys):
            k = keys[i]
            if mib_register(k,unresolved[k], the_mib, {}):
                del(unresolved[k])
                del(keys[i])
                i = 0
            else:
                i += 1
                    
        return True 
開發者ID:medbenali,項目名稱:CyberScan,代碼行數:39,代碼來源:mib.py

示例4: load_mib

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def load_mib(filenames):
    the_mib = {'iso': ['1']}
    unresolved = {}
    for k in conf.mib.keys():
        mib_register(k, conf.mib[k].split("."), the_mib, unresolved)

    if type(filenames) is str:
        filenames = [filenames]
    for fnames in filenames:
        for fname in glob(fnames):
            f = open(fname)
            text = f.read()
            cleantext = " ".join(_mib_re_strings.split(" ".join(_mib_re_comments.split(text))))
            for m in _mib_re_oiddecl.finditer(cleantext):
                gr = m.groups()
                ident,oid = gr[0],gr[-1]
                ident=fixname(ident)
                oid = oid.split()
                for i in range(len(oid)):
                    m = _mib_re_both.match(oid[i])
                    if m:
                        oid[i] = m.groups()[1]
                mib_register(ident, oid, the_mib, unresolved)

    newmib = MIBDict(_name="MIB")
    for k,o in the_mib.iteritems():
        newmib[k]=".".join(o)
    for k,o in unresolved.iteritems():
        newmib[k]=".".join(o)

    conf.mib=newmib 
開發者ID:medbenali,項目名稱:CyberScan,代碼行數:33,代碼來源:mib.py

示例5: load_protocols

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def load_protocols(filename, _fallback=None, _integer_base=10, _cls=DADict):
    """"Parse /etc/protocols and return values as a dictionary."""
    spaces = re.compile(b"[ \t]+|\n")
    dct = _cls(_name=filename)

    def _process_data(fdesc):
        for line in fdesc:
            try:
                shrp = line.find(b"#")
                if shrp >= 0:
                    line = line[:shrp]
                line = line.strip()
                if not line:
                    continue
                lt = tuple(re.split(spaces, line))
                if len(lt) < 2 or not lt[0]:
                    continue
                dct[int(lt[1], _integer_base)] = fixname(lt[0])
            except Exception as e:
                log_loading.info(
                    "Couldn't parse file [%s]: line [%r] (%s)",
                    filename,
                    line,
                    e,
                )
    try:
        if not filename:
            raise IOError
        with open(filename, "rb") as fdesc:
            _process_data(fdesc)
    except IOError:
        if _fallback:
            _process_data(_fallback.split(b"\n"))
        else:
            log_loading.info("Can't open %s file", filename)
    return dct 
開發者ID:secdev,項目名稱:scapy,代碼行數:38,代碼來源:data.py

示例6: ident

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def ident(self, v):
        return fixname(v[0] if isinstance(v, tuple) else v) 
開發者ID:secdev,項目名稱:scapy,代碼行數:4,代碼來源:data.py

示例7: load_mib

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def load_mib(filenames):
    the_mib = {'iso': ['1']}
    unresolved = {}
    for k in conf.mib.keys():
        mib_register(k, conf.mib[k].split("."), the_mib, unresolved)

    if type(filenames) is str:
        filenames = [filenames]
    for fnames in filenames:
        for fname in glob(fnames):
            f = open(fname)
            text = f.read()
            cleantext = " ".join(_mib_re_strings.split(" ".join(_mib_re_comments.split(text))))
            for m in _mib_re_oiddecl.finditer(cleantext):
                gr = m.groups()
                ident,oid = gr[0],gr[-1]
                ident=fixname(ident)
                oid = oid.split()
                for i in range(len(oid)):
                    m = _mib_re_both.match(oid[i])
                    if m:
                        oid[i] = m.groups()[1]
                mib_register(ident, oid, the_mib, unresolved)

    newmib = MIBDict(_name="MIB")
    for k,o in the_mib.items():
        newmib[k]=".".join(o)
    for k,o in unresolved.items():
        newmib[k]=".".join(o)

    conf.mib=newmib 
開發者ID:entynetproject,項目名稱:arissploit,代碼行數:33,代碼來源:mib.py

示例8: load_services

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def load_services(filename):
    spaces = re.compile(b"[ \t]+|\n")
    tdct = DADict(_name="%s-tcp" % filename)
    udct = DADict(_name="%s-udp" % filename)
    try:
        with open(filename, "rb") as fdesc:
            for line in fdesc:
                try:
                    shrp = line.find(b"#")
                    if shrp >= 0:
                        line = line[:shrp]
                    line = line.strip()
                    if not line:
                        continue
                    lt = tuple(re.split(spaces, line))
                    if len(lt) < 2 or not lt[0]:
                        continue
                    dtct = None
                    if lt[1].endswith(b"/tcp"):
                        dtct = tdct
                    elif lt[1].endswith(b"/udp"):
                        dtct = udct
                    else:
                        continue
                    port = lt[1].split(b'/')[0]
                    name = fixname(lt[0])
                    if b"-" in port:
                        sport, eport = port.split(b"-")
                        for i in range(int(sport), int(eport) + 1):
                            dtct[i] = name
                    else:
                        dtct[int(port)] = name
                except Exception as e:
                    log_loading.warning(
                        "Couldn't parse file [%s]: line [%r] (%s)",
                        filename,
                        line,
                        e,
                    )
    except IOError:
        log_loading.info("Can't open /etc/services file")
    return tdct, udct 
開發者ID:secdev,項目名稱:scapy,代碼行數:44,代碼來源:data.py

示例9: _mib_register

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def _mib_register(ident, value, the_mib, unresolved, alias):
    """
    Internal function used to register an OID and its name in a MIBDict
    """
    if ident in the_mib:
        # We have already resolved this one. Store the alias
        alias[".".join(value)] = ident
        return True
    if ident in unresolved:
        # We know we can't resolve this one
        return False
    resval = []
    not_resolved = 0
    # Resolve the OID
    # (e.g. 2.basicConstraints.3 -> 2.2.5.29.19.3)
    for v in value:
        if _mib_re_integer.match(v):
            resval.append(v)
        else:
            v = fixname(plain_str(v))
            if v not in the_mib:
                not_resolved = 1
            if v in the_mib:
                v = the_mib[v]
            elif v in unresolved:
                v = unresolved[v]
            if isinstance(v, list):
                resval += v
            else:
                resval.append(v)
    if not_resolved:
        # Unresolved
        unresolved[ident] = resval
        return False
    else:
        # Fully resolved
        the_mib[ident] = resval
        keys = list(unresolved)
        i = 0
        # Go through the unresolved to update the ones that
        # depended on the one we just did
        while i < len(keys):
            k = keys[i]
            if _mib_register(k, unresolved[k], the_mib, {}, alias):
                # Now resolved: we can remove it from unresolved
                del(unresolved[k])
                del(keys[i])
                i = 0
            else:
                i += 1

        return True 
開發者ID:secdev,項目名稱:scapy,代碼行數:54,代碼來源:mib.py

示例10: load_mib

# 需要導入模塊: from scapy import dadict [as 別名]
# 或者: from scapy.dadict import fixname [as 別名]
def load_mib(filenames):
    """
    Load the conf.mib dict from a list of filenames
    """
    the_mib = {'iso': ['1']}
    unresolved = {}
    alias = {}
    # Export the current MIB to a working dictionary
    for k in six.iterkeys(conf.mib):
        _mib_register(conf.mib[k], k.split("."), the_mib, unresolved, alias)

    # Read the files
    if isinstance(filenames, (str, bytes)):
        filenames = [filenames]
    for fnames in filenames:
        for fname in glob(fnames):
            with open(fname) as f:
                text = f.read()
            cleantext = " ".join(
                _mib_re_strings.split(" ".join(_mib_re_comments.split(text)))
            )
            for m in _mib_re_oiddecl.finditer(cleantext):
                gr = m.groups()
                ident, oid = gr[0], gr[-1]
                ident = fixname(ident)
                oid = oid.split()
                for i, elt in enumerate(oid):
                    m = _mib_re_both.match(elt)
                    if m:
                        oid[i] = m.groups()[1]
                _mib_register(ident, oid, the_mib, unresolved, alias)

    # Create the new MIB
    newmib = MIBDict(_name="MIB")
    # Add resolved values
    for oid, key in six.iteritems(the_mib):
        newmib[".".join(key)] = oid
    # Add unresolved values
    for oid, key in six.iteritems(unresolved):
        newmib[".".join(key)] = oid
    # Add aliases
    for key, oid in six.iteritems(alias):
        newmib[key] = oid

    conf.mib = newmib


####################
#  OID references  #
####################

#      pkcs1       # 
開發者ID:secdev,項目名稱:scapy,代碼行數:54,代碼來源:mib.py


注:本文中的scapy.dadict.fixname方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。