Exemple #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
Exemple #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
Exemple #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()
Exemple #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()
Exemple #5
0
 def __init__(self, email, ip):
     self.email = email
     self.ip = ip
     self.address = get_ip_location(ip)
Exemple #6
0
 def __init__(self, email, ip):
     self.email = email
     self.ip = ip
     self.address = get_ip_location(ip)