统计nginx访问情况
#!/usr/bin/env python #!coding = utf-8 import os vstip = 0 vstime = 0 iplt = {} fl = open("/var/log/nginx/access.log-20190813","r") aclogs=fl.readlines() fl.close() for aclog in aclogs: ipa=aclog.strip().split()[0] # print(ipa + ":" + aclog.split()[3]) if ipa in iplt.keys(): iplt[ipa] = iplt[ipa] + 1 else: iplt[ipa] = 1 for key,value in iplt.items(): vstip += 1 vstime += value print("访问IP: " +key+",访问次数:" +str(value)) print("访问IP总数:" +str(vstip)+ ",访问总次数:" +str(vstime))