码迷,mamicode.com
首页 > 编程语言 > 详细

python统计登录次数

时间:2017-04-16 21:29:50      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:http   ict   where   logs   exec   orm   统计   each   png   

# 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统计登录次数

标签:http   ict   where   logs   exec   orm   统计   each   png   

原文地址:http://www.cnblogs.com/changbo/p/6719812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!