Ejemplo n.º 1
0
def robot(log):
    r = is_robot(log.ip, log.agent)
    if r == 1:
        Blog_info.new_robot_visit(log.date)
    elif r and r != 1:
        try:
            a = socket.gethostbyaddr(log.ip)
            v = ROBOT.get(r)
            if a[0].find(v) >= 0:
                print u'%s -> 新增机器人 IP ----- %s' % (datetime.datetime.now(),
                                                    log.ip)
                rob = Robot(name=r,
                            dns_name=v,
                            ip=log.ip,
                            address=get_ip_location(log.ip))
                db.session.add(rob)
                db.commit()
                Blog_info.new_robot_visit(log.date)  #
                return True
            else:
                alter_ip_blacklist(log, u'爬虫欺骗访问')
                Blog_info.new_attack_visit(log.date)
                return False
        except:
            alter_ip_blacklist(log, u'爬虫欺骗访问')
            Blog_info.new_attack_visit(log.date)
            return False
    else:
        return False
Ejemplo n.º 2
0
def robot(log):
    r = is_robot(log.ip, log.agent)
    if r == 1:
        Blog_info.new_robot_visit(log.date)
    elif r and r != 1:
        try:
            a = socket.gethostbyaddr(log.ip)
            v = ROBOT.get(r)
            if a[0].find(v) >= 0:
                print u'%s -> 新增机器人 IP ----- %s' % (datetime.datetime.now(), log.ip)
                rob = Robot(name=r,
                            dns_name=v,
                            ip=log.ip,
                            address=get_ip_location(log.ip)
                )
                db.session.add(rob)
                db.commit()
                Blog_info.new_robot_visit(log.date)  #
                return True
            else:
                alter_ip_blacklist(log, u'爬虫欺骗访问')
                Blog_info.new_attack_visit(log.date)
                return False
        except:
            alter_ip_blacklist(log, u'爬虫欺骗访问')
            Blog_info.new_attack_visit(log.date)
            return False
    else:
        return False
Ejemplo n.º 3
0
def alter_ip_blacklist(log, reason):
    ip = Ip_blacklist.find_by_ip(log.ip)
    Blog_info.new_attack_visit(log.date)
    if ip:
        print u'%s -> 更新记录 IP ----- %s ,原因 ----- %s' % (datetime.datetime.now(), log.ip, reason)
        ip.visit_count += 1
        ip.attack_count += 1
    else:
        print u'%s -> 新增记录 IP ----- %s ,原因 ----- %s' % (datetime.datetime.now(), log.ip, reason)
        ip = Ip_blacklist(ip=log.ip,
                          address=get_ip_location(log.ip),
                          attack_count=0,
                          is_forbid=0,
                          reason=reason
        )
        ip.forbid_date = datetime.date.today()
    db.session.add(ip)
    db.session.commit()
Ejemplo n.º 4
0
def alter_ip_blacklist(log, reason):
    ip = Ip_blacklist.find_by_ip(log.ip)
    Blog_info.new_attack_visit(log.date)
    if ip:
        print u'%s -> 更新记录 IP ----- %s ,原因 ----- %s' % (
            datetime.datetime.now(), log.ip, reason)
        ip.visit_count += 1
        ip.attack_count += 1
    else:
        print u'%s -> 新增记录 IP ----- %s ,原因 ----- %s' % (
            datetime.datetime.now(), log.ip, reason)
        ip = Ip_blacklist(ip=log.ip,
                          address=get_ip_location(log.ip),
                          attack_count=0,
                          is_forbid=0,
                          reason=reason)
        ip.forbid_date = datetime.date.today()
    db.session.add(ip)
    db.session.commit()
Ejemplo n.º 5
0
 def __init__(self, email, ip):
     self.email = email
     self.ip = ip
     self.address = get_ip_location(ip)
Ejemplo n.º 6
0
 def __init__(self, email, ip):
     self.email = email
     self.ip = ip
     self.address = get_ip_location(ip)