예제 #1
0
	def test_geoip_raw_geolocation(self):
		loc = geoip.GeoLocation(GEO_TEST_IP)
		loc_raw = geoip.GeoLocation(GEO_TEST_IP, result=geoip.lookup(GEO_TEST_IP))
		for field in geoip.DB_RESULT_FIELDS:
			self.assertEqual(getattr(loc, field), getattr(loc_raw, field))
		self.assertIsInstance(loc.ip_address, ipaddress.IPv4Address)
		self.assertEqual(loc.ip_address, ipaddress.ip_address(GEO_TEST_IP))
예제 #2
0
	def from_ip_address(cls, ip_address):
		ip_address = ipaddress.ip_address(ip_address)
		if ip_address.is_private:
			return
		result = geoip.lookup(ip_address)
		if result is None:
			return
		return cls(**result)
예제 #3
0
	def from_ip_address(cls, ip_address):
		ip_address = ipaddress.ip_address(ip_address)
		if ip_address.is_private:
			return
		try:
			result = geoip.lookup(ip_address)
		except geoip2.errors.AddressNotFoundError:
			result = None
		if result is None:
			return
		return cls(**result)
예제 #4
0
	def rpc_geoip_lookup(self, ip, lang=None):
		"""
		Look up an IP address in the servers GeoIP database. If the IP address
		can not be found in the database, None will be returned.

		:param str ip: The IP address to look up.
		:param str lang: The language to prefer for regional names.
		:return: The geographic information for the specified IP address.
		:rtype: dict
		"""
		try:
			result = geoip.lookup(ip, lang=lang)
		except geoip.AddressNotFoundError:
			result = None
		return result
예제 #5
0
	def rpc_geoip_lookup_multi(self, ips, lang=None):
		"""
		Look up multiple IP addresses in the servers GeoIP database. Each IP
		address that can not be found in the database will have its result set
		to None.

		:param list ips: The list of IP addresses to look up.
		:param str lang: The language to prefer for regional names.
		:return: A dictionary containing the results keyed by the specified IP
			addresses.
		:rtype: dict
		"""
		results = {}
		for ip in ips:
			try:
				result = geoip.lookup(ip, lang=lang)
			except geoip.AddressNotFoundError:
				result = None
			results[ip] = result
		return results
def rest_api_geoip_lookup(handler, params):
	ip = handler.get_query('ip')
	assert ip
	return geoip.lookup(ip)
예제 #7
0
	def test_geoip_lookup_ipv6(self):
		with self.assertRaises(TypeError):
			geoip.lookup('2607:f8b0:4002:c07::68')
예제 #8
0
	def test_geoip_lookup_private(self):
		with self.assertRaises(RuntimeError):
			geoip.lookup('192.168.1.1')
예제 #9
0
	def test_geoip_lookup(self):
		result = geoip.lookup(GEO_TEST_IP)
		self.assertIsInstance(result, dict)
		for field in geoip.DB_RESULT_FIELDS:
			self.assertIn(field, result)
예제 #10
0
 def test_geoip_lookup_ipv6(self):
     with self.assertRaises(TypeError):
         geoip.lookup('2607:f8b0:4002:c07::68')
예제 #11
0
 def test_geoip_lookup_private(self):
     with self.assertRaises(RuntimeError):
         geoip.lookup('192.168.1.1')
예제 #12
0
 def test_geoip_lookup(self):
     result = geoip.lookup(GEO_TEST_IP)
     self.assertIsInstance(result, dict)
     for field in geoip.DB_RESULT_FIELDS:
         self.assertIn(field, result)
예제 #13
0
def rest_api_geoip_lookup(handler, params):
    ip = handler.get_query('ip')
    assert ip
    return geoip.lookup(ip)
예제 #14
0
def rest_api_geoip_lookup(handler, params):
    ip = handler.get_query("ip")
    if not ip:
        logger.error("the required 'ip' parameter is missing for geoip/lookup")
        raise errors.KingPhisherAPIError("the required 'ip' parameter is missing for geoip/lookup")
    return geoip.lookup(ip)