时间:2021-07-01 10:21:17 帮助过:28人阅读
比如,服务器上有nginx的log如下:
221.221.155.54 - - [02/Aug/2014:15:16:11 +0800] "GET / HTTP/1.1" 200 8482 "http://www.zuidaima.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36" "-" "0.020"
221.221.155.53 - - [02/Aug/2014:15:16:11 +0800] "GET / HTTP/1.1" 200 8482 "http://www.zuidaima.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36" "-" "0.020"
221.221.155.54 - - [02/Aug/2014:15:16:11 +0800] "GET / HTTP/1.1" 200 8482 "http://www.zuidaima.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36" "-" "0.020"
统计脚本如下:
stat_ip.py
#encoding=utf8运行结果如下:
ip: 221.221.155.53 ,views: 1
ip: 221.221.155.54 ,views: 2
total: 2
max_ip_view: {'221.221.155.54': 2}
这样得到了所有ip的访问量及其最大ip的访问。
以上就介绍了python基于nginx访问日志统计客户端ip访问量,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。