本文主要是介绍python 分析access.log,根据IP粗略统计次数,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
python 分析access.log,根据IP粗略统计次数,
#-*- coding: utf-8 -*-
import sys
import os
import pandas as pd
from collections import Counter
import xlwt
import redef getlog():current_dir=os.path.dirname(__file__)logdir="E:/mypython/mypython123/log/log"#日志文件所在目录#存放统计所需的日志相关字段logfile_format=os.path.join(current_dir,"log.txt")for eachfile in os.listdir(logdir):logfile=os.path.join(logdir,eachfile)with open(logfile, 'r') as fo:for line in fo:spline=line.split()#过滤字段中异常部分if spline[0]=="127.0.0.1":passelse:print(spline)# print("IP:{}时间:{}接口:{}".format(spline[0],spline[3],spline[6]))
这篇关于python 分析access.log,根据IP粗略统计次数的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!