zoukankan      html  css  js  c++  java
  • python统计登录次数

    # coding:utf-8
    
    # ==================================================================================
    # Author: changbo - EMail:changbo@hmg100.com
    # Last modified:2017-4-16
    # filename:run_status.py
    # Description:check nginx access.log, Base
    # blog:http://www.cnblogs.com/changbo
    # ==================================================================================
    
    # check login times of IP (Login password explosion)
    
    # whiteIP = ['127.0.0.1', ]
    
    from collections import Counter
    import pymysql
    
    seachtime = '2017-4-07'
    db = pymysql.connect("x.x.x.x", "xxxx", "xxxxx", "xxxxx")
    cursor = db.cursor()
    
    # sqlcommd = "INSERT INTO abnormal(ip, time, url) VALUES('%s' ,'%s' ,'%s')" % (ip1, time1, url1)
    sqlcommd1 = "select time FROM abnormal where date='%s'" % seachtime
    
    try:
        logintime = []
        cursor.execute(sqlcommd1)
        db.commit()
        results = cursor.fetchall()
        for i in range(len(results)):
            logintime.append(('%s' % results[i])[:5])
        print(dict(Counter(logintime)))
    except Exception as e:
        print(e)
    db.close()
    

     图示如下

     END!

  • 相关阅读:
    Windows 服务程序(一)
    API---注册表编程
    API---文件操作
    main(argc, char *argv[])
    C 自删除技术---批处理方式
    分治法排序
    TDD尝试:nodejs单元测试
    尝试create tech team
    Yum重装走过的坑
    求生欲很强的数据库
  • 原文地址:https://www.cnblogs.com/changbo/p/6719812.html
Copyright © 2011-2022 走看看