我正在寻找一个更好(更快)的方法来处理这个问题。我的问题是,当你增加“主机”列表的长度时,程序要花费成倍的时间才能完成,如果“主机”足够长,那么程序完成所需的时间就太长了,以至于它似乎只是在锁定。在
我目前的方法是使用CSV文件中的regex模式搜索“hosts”i[7]元素中包含的每个多行列表项。有100个可能的匹配项,我需要识别与每个IP地址相关联的所有匹配项,并从CSV文件中分配唯一的字符串来标识所有模式匹配项。最后,我需要将这些信息放入“fullMatchList”中以便以后使用。在
注意:即使“searchPatterns”中的每个列表项最多有4个模式,我只需要它来标识找到的第一个模式,然后它就可以转到下一个列表项,继续为该IP查找匹配项。在
for i in hosts:
if i[4] == "13579" or i[4] == "24680":
for j in searchPatterns:
for k in range(4):
if j[k] == "SKIP":
continue
else:
match = re.search(r'%s' % j[k], i[7], flags=re.DOTALL)
if match is not None:
if tempIP == "":
tempIP = i[0]
matchListPerIP.append(j[4])
elif tempIP == i[0]:
matchListPerIP.append(j[4])
elif tempIP != i[0]:
fullMatchList.append([tempIP, matchListPerIP])
tempIP = i[0]
matchListPerIP = []
matchListPerIP.append(j[4])
break
fullMatchList.append([tempIP, matchListPerIP])
以下是来自CSV文件的regex搜索模式示例:(?!(.*?)\br2\b)cpe:/o:microsoft:windows_server_2008:
该模式旨在标识WindowsServer2008,并包含一个否定的前瞻性,以避免与R2版本匹配。在
我是Python的新手,所以任何建议都将不胜感激!谢谢您!在
NIDS社区已经做了大量的工作,针对一长串regex(防火墙规则)测试相同的字符串(网络包)。在
我还没有读过相关文献,但是Coit等人的“为入侵检测提供更快的字符串匹配或超过Snort的速度”似乎是一个很好的起点。在
引自引言:
相关问题 更多 >
编程相关推荐