zoukankan      html  css  js  c++  java
  • day4_监控日志的脚本

    import time
    pointer = 0 # 存文件指针变量
    while True:
    with open('access.log') as fr: # access.log文件在pycharm的day4里
    ips = []
    fr.seek(pointer) # 移动指针
    for line in fr:
    ip = line.split()[0]
    ips.append(ip)
    new_ips = set(ips) # 使用集合过滤,去掉重复的ip
    for new_ip in new_ips:
    if ips.count(new_ip) > 200:
    print('要把这个ip加入黑名单:%s' % new_ip)
    pointer = fr.tell() # 记录文件指针的位置,即文件指针当前位置
    time.sleep(60)
  • 相关阅读:
    C语言I博客作业09
    C语言I博客作业08
    14
    13
    12
    11
    10
    9
    8
    7
  • 原文地址:https://www.cnblogs.com/laosun0204/p/8493875.html
Copyright © 2011-2022 走看看