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
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
def is_robot(ip, agent): ro = Robot.query.filter_by(ip=ip).first() if ro: return 1 else: for r in ROBOT.keys(): if agent.find(r) >= 0: return r else: return False