Exemplo n.º 1
0
 def test_geoip_v6_privex1(self):
     """Test ``2a07:e00::333`` resolves correctly using :meth:`.geoip.geolocate_ip`"""
     data = geoip.geolocate_ip('2a07:e00::333')
     self.assertIn(data.as_name, self.AS_NAMES.privex)
     self.assertEqual(data.as_number, 210083)
     self.assertEqual(data.country, 'Sweden')
     self.assertEqual(data.country_code, 'SE')
     self.assertEqual(data.city, 'Stockholm')
     # GeoIP's network value isn't reliable, so we simple check it starts with 2a07:e00::/
     self.assertIn('2a07:e00::/', str(data.network))
Exemplo n.º 2
0
 def test_geoip_v4_hetzner1(self):
     """Test ``95.216.3.171`` resolves correctly using :meth:`.geoip.geolocate_ip`"""
     data = geoip.geolocate_ip('95.216.3.171')
     self.assertIn(data.as_name, self.AS_NAMES.hetzner)
     self.assertEqual(data.as_number, 24940)
     self.assertEqual(data.country, 'Finland')
     self.assertEqual(data.country_code, 'FI')
     self.assertIn(data.city, [None, 'Helsinki'])
     # GeoIP's network value isn't reliable, so we simply check the first 5 characters, and confirm there's a / present
     self.assertTrue(str(data.network).startswith('95.21'))
     self.assertIn('/', str(data.network))
Exemplo n.º 3
0
 def test_geoip_v4_privex1(self):
     """Test ``185.130.44.5`` resolves correctly using :meth:`.geoip.geolocate_ip`"""
     data = geoip.geolocate_ip('185.130.44.5')
     self.assertIn(data.as_name, self.AS_NAMES.privex)
     self.assertEqual(data.as_number, 210083)
     self.assertEqual(data.country, 'Sweden')
     self.assertEqual(data.country_code, 'SE')
     self.assertEqual(data.city, 'Stockholm')
     self.assertIn(
         str(data.network),
         ['185.130.44.0/24', '185.130.44.0/23', '185.130.44.0/22'])
Exemplo n.º 4
0
 def test_geoip_v6_hetzner1(self):
     """Test ``2a01:4f9:2a:3d4::2`` resolves correctly using :meth:`.geoip.geolocate_ip`"""
     data = geoip.geolocate_ip('2a01:4f9:2a:3d4::2')
     self.assertIn(data.as_name, self.AS_NAMES.hetzner)
     self.assertEqual(data.as_number, 24940)
     self.assertIn(data.geoasn_data.autonomous_system_organization,
                   self.AS_NAMES.hetzner)
     self.assertEqual(data.geoasn_data.autonomous_system_number, 24940)
     # Hetzner's IPv6 range is quirky with GeoIP2. As of 2020-05-17, it's incorrectly reporting Germany for a Finnish IPv6 address.
     # To avoid the test breaking in the future, we'll allow either Finland or Germany.
     self.assertIn(data.country, ['Finland', 'Germany'])
     self.assertIn(data.country_code, ['FI', 'DE'])
     # Again, the IPv6 network that this address belongs to can fluctuate - so we just make sure it starts with 2a01:4f
     self.assertTrue(str(data.network).startswith('2a01:4f'))
     self.assertIn('/', str(data.network))
Exemplo n.º 5
0
 def test_geoip_v6_local_no_throw(self):
     data = geoip.geolocate_ip('fe80::1', throw=False)
     self.assertIsNone(data)
Exemplo n.º 6
0
 def test_geoip_v4_local_no_throw(self):
     data = geoip.geolocate_ip('192.168.5.1', throw=False)
     self.assertIsNone(data)
Exemplo n.º 7
0
 def test_geoip_v6_local(self):
     with self.assertRaises(GeoIPAddressNotFound):
         geoip.geolocate_ip('fe80::1')
Exemplo n.º 8
0
 def test_geoip_v4_local(self):
     with self.assertRaises(GeoIPAddressNotFound):
         geoip.geolocate_ip('192.168.5.1')