python统计登录次数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python统计登录次数相关的知识,希望对你有一定的参考价值。

# coding:utf-8

# ==================================================================================
# Author: changbo - EMail:[email protected]
# 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!

以上是关于python统计登录次数的主要内容,如果未能解决你的问题,请参考以下文章

scala实战之spark用户在线时长和登录次数统计实例

python代码统计字符串中大写字符小写字符特殊字符以及数值字符出现的次数

python字符串出现次数

python 编写代码首先生成包含1000个随机字符的字符串,然后统计每个字符的出现次数。

Python3红楼梦人名出现次数统计分析

python之pygal:掷两个不同的骰子并统计大小出现次数