__author__ = ‘Administrator‘ import re ipa = {} err_nb = {} IES = {} IES[‘AB‘] = [‘MSIE‘, ‘Firefox‘, ‘Chrome‘] Logfile = ‘./access_log‘ f=open(Logfile, ‘r‘).readlines() for i in f: ip=i.split() #print(ip[-8]) for n in IES[‘AB‘]: if re.search(n, i): if IES.get(n) == None: IES.setdefault(n,1) else: IES[n]+=1 if ipa.get(ip[0]) == None: ipa.setdefault(ip[0], 1) else: ipa[ip[0]]+=1 if err_nb.get(ip[8]) == None: err_nb.setdefault(ip[8], 1) else: err_nb[ip[8]] += 1 print(‘IP访问次数:‘) sorted(ipa.items()) for i in ipa: print(i, ‘----->‘, ipa.get(i)) print(‘HTTP状态码数目:‘) sorted(err_nb.items(), reverse=False) for i in err_nb: print(i,‘----->‘,err_nb.get(i)) print(‘浏览器访问的数目:‘,IES.get(‘AB‘)) sorted(IES.items(),reverse=True) for i in IES: if i == ‘AB‘: continue print(i,‘----->‘,IES.get(i))
running:
IP访问次数:
192.168.182.1 -----> 222
192.168.182.130 -----> 9
::1 -----> 6
HTTP状态码数目:
304 -----> 152
200 -----> 16
404 -----> 69
浏览器访问的数目: [‘MSIE‘, ‘Firefox‘, ‘Chrome‘]
Chrome -----> 122
Firefox -----> 67
MSIE -----> 33
时间: 2024-11-05 17:25:33