def nginxIpCounter(nginxFile):
ipCounter = { }
with open(nginxFile) as f:
for line in f:
ip = line.split(" ",1)[0]
if 6<=len(ip) <= 15:
ipCounter[ip] = ipCounter.get(ip,0) + 1
return ipCounter
nginxIp = { }
nginxIpBySort = { }
nginxIp = nginxIpCounter("/root/nginx_ip.test")
nginxIpBySort = sorted(nginxIp.iteritems(),key = lambda d:d[1] ,reverse = True)
for i,j in nginxIpBySort:
print "%s => %d"%(i,j)
python小程序:查找nginx日志文件的ip点击率并排序
最新推荐文章于 2024-04-08 14:22:17 发布