Python分析iis日志
Python实现分析出iis日志中每个ip一分钟出现的访问次数
1 #iis日志分析,计算每个ip在一分钟内的访问次数 2 from collections import Counter 3 import datetime 4 5 f=open("log.log","r") 6 pv_list=[] 7 for line in f: 8 if len(line.split())==15: 9 #print(line.split()[0:2]) 10 func_time=line.split()[0]+" "+line.split()[1] 11 same_time=func_time.split(":")[0:2] 12 ip_time=line.split()[8]+" "+func_time.split(":")[0]+func_time.split(":")[1] 13 pv_list.append(ip_time) 14 pv_time_ip=Counter(pv_list) 15 for ip in pv_time_ip.keys(): 16 print("%s has visited my web %s in %s" % (ip.split()[0], pv_time_ip[ip],ip.split()[1:3]))