把做工程过程中比较好的代码片段做个备份, 下面资料是关于 python 分析 apache 和 nginx 日志文件输出访客 ip 列表的代码.
- ips = {}
- fh = open("/var/log/nginx/access.log", "r").readlines()
- for line in fh:
- ip = line.split(" ")[0]
- if 6 < len(ip) <=15:
- ips[ip] = ips.get(ip, 0) + 1
- print ips
来源: http://www.bubuko.com/infodetail-2945455.html