I have a python script which extracts unique ip addresses from snort log but how to modify or use regex to extract IPs only if they are logged more than 10 times per second? more specific: using "regex", if the second (i.e 41 in this scenario) doesn't change for more than 10 lines of having the same IP address then extract that IP.
blacklist = list(open("/home/asad/blackdb/blacklist", 'r').read().split('\n'))
logfile = list(open('/home/asad/logdb/snort.alert', 'r').read().split('\n'))
newip = []
for entry in logfile:
ips = re.findall(r'[0-9]+(?:\.[0-9]+){3}', entry)
for ip in ips:
newip.append(ip)
newblist = blacklist + newip
with open("/home/asad/blackdb/blacklist", 'w+') as f:
f.write('\n' .join(set(newblist))+'\n\n')
f.close()
log example text format:
`12/30-04:09:41.070967 [**] [1:10000001:1] snort alert [1:0000001] [**] [classification ID: 0] [Priority ID: 0] {ICMP} 192.168.232.2:41676 -> 192.168.248.2:21`
`12/30-04:09:41.070967 [**] [1:10000001:1] snort alert [1:0000001] [**] [classification ID: 0] [Priority ID: 0] {ICMP} 192.168.232.2:41673 -> 192.168.248.2:21`
in above log, in both lines seconds are: 41 and IPs are: 192.168.232.2 and 192.168.248.2. If there are >10 records in the same second i.e 41, then it should extract it.
any help please?