Пример #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
Пример #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