diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ipaddress.py | 7 | ||||
-rw-r--r-- | Lib/test/test_ipaddress.py | 3 |
2 files changed, 10 insertions, 0 deletions
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py index ca3031a..1f90058 100644 --- a/Lib/ipaddress.py +++ b/Lib/ipaddress.py @@ -1312,6 +1312,11 @@ class IPv4Address(_BaseV4, _BaseAddress): return any(self in net for net in self._constants._private_networks) @property + @functools.lru_cache() + def is_global(self): + return self not in self._constants._public_network and not self.is_private + + @property def is_multicast(self): """Test if the address is reserved for multicast use. @@ -1557,6 +1562,8 @@ class _IPv4Constants: _multicast_network = IPv4Network('224.0.0.0/4') + _public_network = IPv4Network('100.64.0.0/10') + _private_networks = [ IPv4Network('0.0.0.0/8'), IPv4Network('10.0.0.0/8'), diff --git a/Lib/test/test_ipaddress.py b/Lib/test/test_ipaddress.py index 3edea08..be62fad 100644 --- a/Lib/test/test_ipaddress.py +++ b/Lib/test/test_ipaddress.py @@ -1626,6 +1626,9 @@ class IpaddrUnitTest(unittest.TestCase): self.assertEqual(False, ipaddress.ip_address('169.255.100.200').is_link_local) + self.assertTrue(ipaddress.ip_address('192.0.7.1').is_global) + self.assertFalse(ipaddress.ip_address('203.0.113.1').is_global) + self.assertEqual(True, ipaddress.ip_address('127.100.200.254').is_loopback) self.assertEqual(True, ipaddress.ip_address('127.42.0.0').is_loopback) |