zoukankan      html  css  js  c++  java
  • tomcat日志文件 访问IP统计

    tomcat  localhost_access_log.2018-09-19.txt日志文件 访问IP统计

    172.16.8.11 - - [19/Sep/2018:12:35:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.1 - - [19/Sep/2018:12:43:08 +0800] "GET /images/loading.gif HTTP/1.1" 200 404
    172.16.8.1 - - [19/Sep/2018:12:43:08 +0800] "POST /init HTTP/1.1" 200 207
    172.16.8.1 - - [19/Sep/2018:12:43:12 +0800] "POST /init HTTP/1.1" 200 207
    172.16.8.1 - - [19/Sep/2018:12:43:16 +0800] "GET / HTTP/1.1" 200 7612
    172.16.8.1 - - [19/Sep/2018:12:43:16 +0800] "GET /css/default-init.css?1537325099834 HTTP/1.1" 304 -
    172.16.8.1 - - [19/Sep/2018:12:43:16 +0800] "GET /js/lib/jquery/jquery.min.js HTTP/1.1" 304 -
    172.16.8.1 - - [19/Sep/2018:12:43:16 +0800] "GET /images/logo.png HTTP/1.1" 304 -
    172.16.8.11 - - [19/Sep/2018:12:45:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:12:55:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:13:05:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:13:15:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.11 - - [19/Sep/2018:13:25:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.11 - - [19/Sep/2018:13:35:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.11 - - [19/Sep/2018:13:45:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    172.16.8.11 - - [19/Sep/2018:13:55:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:05:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:15:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:25:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:35:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7612
    172.16.8.11 - - [19/Sep/2018:14:45:21 +0800] "GET /console/stat/onlineVisitorRefresh HTTP/1.1" 200 7613
    SHELL脚本

    [root@localhost logs]# awk '{aaa[$1]++;} END{for(i in aaa) { printf("%s %s ", aaa[i], i); }}' localhost_access_log.2018-09-19.txt | sort -bn
    2    127.0.0.1
    24    172.16.8.1
    26    172.16.8.11
    [root@localhost logs]# grep -i -o -E -r -e "([0-9]{1,3}.){3}[0-9]{1,3}" localhost_access_log.2018-09-19.txt | sort -n | uniq -c | sort -n
          2 127.0.0.1
         24 172.16.8.1
         26 172.16.8.11
    [root@localhost logs]# awk '{print $1}' localhost_access_log.2018-09-19.txt | grep -E "([0-9]{1,3}.){3}[0-9]{1,3}" | sort | uniq -c | sort -g
          2 127.0.0.1
         24 172.16.8.1
         26 172.16.8.11
    PYTHON脚本

    cat log.py 
    import re
    mydict = {}
    with open('localhost_access_log.2018-09-19.txt') as f:
            for line in f:
                    match = re.match(r'([0-9]{1,3}.){3}[0-9]{1,3}', line)
                    if match:
                            ip = match.group()
                            if ip in mydict.keys():
                                    mydict[ip] += 1
                            else:
                                    mydict[ip] = 1

    print mydict

    执行结果
    [root@localhost logs]# python log.py 
    {'172.16.8.1': 24, '172.16.8.11': 27, '127.0.0.1': 2}
    ---------------------
    作者:思考v
    来源:CSDN
    原文:https://blog.csdn.net/xiegh2014/article/details/82772327
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    C#使用Xamarin开发可移植移动应用(5.进阶篇显示弹出窗口与通讯中心)附源码
    C#使用Xamarin开发可移植移动应用(4.进阶篇MVVM双向绑定和命令绑定)附源码
    C#使用Xamarin开发可移植移动应用(3.Xamarin.Views控件)附源码
    C#使用Xamarin开发可移植移动应用(2.Xamarin.Forms布局,本篇很长,注意)附源码
    C#使用Xamarin开发可移植移动应用(1.入门与Xamarin.Forms页面),附源码
    ASP.NET Core之跨平台的实时性能监控(2.健康检查)
    Android Studio 快捷键:重载与重写、try catch代码块、导包 快捷键
    新版本jQuery对动态添加元素绑定点击事件实例
    ssm框架中,mybatis的sql语句日志输出
    maven环境下的ssm框架上传excel 案例
  • 原文地址:https://www.cnblogs.com/henrylinux/p/9931403.html
Copyright © 2011-2022 走看看