Esempio n. 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))
Esempio n. 2
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))
Esempio n. 3
0
    def lookup(self, addr):
        data = DictObject()
        data.addr = addr
        data.internal = False

        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 = None

        else:
            addrlong = ip2long(addr)

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

        if match:
            return data
        else:
            return None
Esempio n. 4
0
    def lookup(self, addr):
        data = DictObject()
        data.addr = addr
        data.internal = False

        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 = None

        else:
            addrlong = ip2long(addr)
            
            for location in Location.objects.all():
                if ((addrlong & ip2long(location.mask)) == ip2long(location.address)):
                    data.latitude = location.latitude
                    data.longitude = location.longitude
                    data.name = location.name
                    data.internal = True
                    match = True
                    break

        if match:
            return data
        else:
            return None