def default(request): """ """ logger = logging.getLogger("default") ip_client_string = get_client_ip(request) ip_client_value = ip_convert.ipv4_from_string(ip_client_string) logger.debug("from " + ip_client_string) if COOKIE_QUERY_HISTORY in request.COOKIES: new_query_history = request.COOKIES[COOKIE_QUERY_HISTORY] try: new_query_history = json.loads(new_query_history) except json.ReadError: new_query_history = [] return render_to_response("ipinfo.html", locals())
def default(request): """ """ logger = logging.getLogger('default') ip_client_string = get_client_ip(request) ip_client_value = ip_convert.ipv4_from_string(ip_client_string) logger.debug('from ' + ip_client_string) if COOKIE_QUERY_HISTORY in request.COOKIES: new_query_history = request.COOKIES[COOKIE_QUERY_HISTORY] try: new_query_history = json.loads(new_query_history) except json.ReadError: new_query_history = [] return render_to_response('ipinfo.html', locals())
def query_by_ipv4_inner(request, ipv4): """ """ logger = logging.getLogger("query_by_ipv4_inner") ip_infos = models.Ipv4Info.objects.filter_by_ip(ipv4)[:5] ip_string = ip_convert.ipv4_to_string(ipv4) ip_value = ip_convert.ipv4_int2readable(ipv4) ip_client_string = get_client_ip(request) ip_client_value = ip_convert.ipv4_from_string(ip_client_string) logger.debug("from " + ip_client_string + " query " + ip_string + " return " + str(ip_infos.count()) + " results") new_query_history = [] if ip_infos.count() > 0: new_query_history.append([ip_string, unicode(ip_infos[0])]) if COOKIE_QUERY_HISTORY in request.COOKIES: old_query_history = request.COOKIES[COOKIE_QUERY_HISTORY] try: old_query_history = json.loads(old_query_history) except json.ReadError: old_query_history = [] old_query_history = uniq(old_query_history) new_query_history.extend(old_query_history) new_query_history = uniq(new_query_history)[:MAX_QUERY_HISTORY] response = render_to_response("ipinfo.html", locals()) try: new_query_history_str = json.dumps(new_query_history) response.set_cookie( key=COOKIE_QUERY_HISTORY, value=new_query_history_str, max_age=86400, expires=None, path="/", domain=None, secure=None, ) except json.WriteError: response.delete_cookie(key=COOKIE_QUERY_HISTORY) print "write error: " print new_query_history except json.UnknownSerializerError: response.delete_cookie(key=COOKIE_QUERY_HISTORY) print "error" return response
def query_by_ipv4_inner(request, ipv4): """ """ logger = logging.getLogger('query_by_ipv4_inner') ip_infos = models.Ipv4Info.objects.filter_by_ip(ipv4)[:5] ip_string = ip_convert.ipv4_to_string(ipv4) ip_value = ip_convert.ipv4_int2readable(ipv4) ip_client_string = get_client_ip(request) ip_client_value = ip_convert.ipv4_from_string(ip_client_string) logger.debug('from ' + ip_client_string + ' query ' + ip_string + ' return ' + str(ip_infos.count()) + ' results') new_query_history = [] if ip_infos.count() > 0: new_query_history.append([ip_string, unicode(ip_infos[0])]) if COOKIE_QUERY_HISTORY in request.COOKIES: old_query_history = request.COOKIES[COOKIE_QUERY_HISTORY] try: old_query_history = json.loads(old_query_history) except json.ReadError: old_query_history = [] old_query_history = uniq(old_query_history) new_query_history.extend(old_query_history) new_query_history = uniq(new_query_history)[:MAX_QUERY_HISTORY] response = render_to_response('ipinfo.html', locals()) try: new_query_history_str = json.dumps(new_query_history) response.set_cookie(key=COOKIE_QUERY_HISTORY, value=new_query_history_str, max_age=86400, expires=None, path='/', domain=None, secure=None) except json.WriteError: response.delete_cookie(key=COOKIE_QUERY_HISTORY) print 'write error: ' print new_query_history except json.UnknownSerializerError: response.delete_cookie(key=COOKIE_QUERY_HISTORY) print 'error' return response
def query_by_ipv4_string(request, ipv4_string): """ """ ipv4 = ip_convert.ipv4_from_string(ipv4_string) return query_by_ipv4(request, ipv4)