Exemple #1
0
def getLocation(request, name):
    try:
        loc = Location.objects.get(name=name)
    except ObjectDoesNotExist:
        return Http404

    d = DictObject()
    d.name = loc.name
    # d.address = loc.address
    # d.mask = loc.mask
    d.latitude = loc.latitude
    d.longitude = loc.longitude

    return HttpResponse(json.dumps(d))
def getLocation(request, name):
    try:
        loc = Location.objects.get(name=name);
    except ObjectDoesNotExist:
        return Http404

    d = DictObject()
    d.name = loc.name
    # d.address = loc.address
    # d.mask = loc.mask
    d.latitude = loc.latitude
    d.longitude = loc.longitude

    return HttpResponse(json.dumps(d))
    def lookup(self, addr):
        addrlong = ip2long(addr)

        data = DictObject()
        data.addr = addr

        for location_ip in LocationIP.objects.all():
            if ((addrlong & ip2long(location_ip.mask)) == ip2long(location_ip.address)):
                location = location_ip.location
                data.latitude = location.latitude
                data.longitude = location.longitude
                data.name = location.name
                match = True
                break

        if match:
            return data
        else:
            return None
Exemple #4
0
    def lookup(self, addr):
        addrlong = ip2long(addr)

        data = DictObject()
        data.addr = addr

        for location_ip in LocationIP.objects.all():
            if ((addrlong & ip2long(location_ip.mask)) == ip2long(
                    location_ip.address)):
                location = location_ip.location
                data.latitude = location.latitude
                data.longitude = location.longitude
                data.name = location.name
                match = True
                break

        if match:
            return data
        else:
            return None
    def lookup(self, addr):
        data = DictObject()
        data.addr = addr

        with lookup_lock:
            r = self.geoip.record_by_addr(addr)

        match = False

        if r is not None:
            data.latitude = r['latitude']
            data.longitude = r['longitude']
            match = True
            try:
                (n, x, y) = socket.gethostbyaddr(addr)
                data.name = n
            except:
                data.name = addr

            return data
        else:
            return None
Exemple #6
0
    def lookup(self, addr):
        data = DictObject()
        data.addr = addr

        with lookup_lock:
            r = self.geoip.record_by_addr(addr)

        match = False

        if r is not None:
            data.latitude = r['latitude']
            data.longitude = r['longitude']
            match = True
            try:
                (n, x, y) = socket.gethostbyaddr(addr)
                data.name = n
            except:
                data.name = addr

            return data
        else:
            return None