首页 > 代码库 > python统计登录次数
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!
python统计登录次数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。