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): 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