本文整理汇总了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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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 #