我目前需要使用 Python 2.7 比较包含 MAC 地址的字符串(例如“11:22:33:AA:BB:CC”。目前,我有一个包含 MAC 地址的预配置集,我的脚本会迭代通过集合将每个新的 MAC 地址与列表中的地址进行比较。这很有效,但是随着集合的增长,脚本会大大减慢。只有 100 个左右,您会注意到巨大的差异。
有人对加快这个过程有什么建议吗?将它们存储在一组中是比较的最佳方式,还是将它们存储在 CSV / DB 中更好?
代码示例...
def Detect(p):
stamgmtstypes = (0,2,4)
if p.haslayer(Dot11):
if p.type == 0 and p.subtype in stamgmtstypes:
if p.addr2 not in observedclients:
# This is the set with location_mutex:
detection = p.addr2 + "\t" + str(datetime.now())
print type(p.addr2)
print detection, last_location
observedclients.append(p.addr2)