Monitor server logs to find access more than 100 times per minute ip address

# 1, monitor server logs to find access more than 100 times per minute ip address 
# Analysis:
# 1, read documents, access to all the files inside ip address
# 2, the ip address to save it with a dictionary memory, key ip address is, value is the number of
# 3, the dictionary cycle, the determined value is larger than 100

# log contents analysis
# 37.9.169.20 - - [04 / Jun / 2017: 03: 48: 21 +0800] "GET / wp-admin / security.php HTTP / 1.1 "302 161" http://nnzhp.cn/wp-admin/security.php "" Mozilla / 5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit / 533.4 (KHTML, like the Gecko) the Chrome / 5.0.375.99 Safari / 533.4 "" - "



Import Time
Point 0 =
the while True:
IPS #} = {ip address and store all times it appears
F = Open ( 'the access.log')
f.seek (Point)
for in line F:
IF line.strip (): # when it is determined that no blank line
ip = line.split () [0] # accordance separated by spaces, i.e., a first and takes (log contents accessible to the analysis inside the IP)
IF IP Not in IPS:
IPS [IP] =. 1
the else:
IPS [IP] IPS = [IP] + 1'd
Point = f.tell () # current file pointer position
for IP in IPS:
IF ips.get (IP)> = 100:
Print ( 'ip is more than 100 times: S%'% ip)
the time.sleep (60) # statistics once per minute

Guess you like

Origin www.cnblogs.com/zhumintest/p/11616880.html