Lines Matching refs:ipaddress
12 import ipaddress
58 return self.assertCleanError(ipaddress.AddressValueError,
63 return self.assertCleanError(ipaddress.NetmaskValueError,
196 factory = ipaddress.IPv4Address
199 v4 = ipaddress.IPv4Address("1.2.3.42")
226 ipaddress.IPv4Address(addr)
231 ipaddress.IPv4Address(addr)
261 ipaddress.IPv4Address(addr)
270 ipaddress.IPv4Address(addr)
286 ipaddress.IPv4Address(addr)
295 ipaddress.IPv4Address(addr)
308 factory = ipaddress.IPv6Address
312 v6 = ipaddress.IPv6Address("::1.2.3.42")
355 ipaddress.IPv6Address(addr)
363 ipaddress.IPv6Address(addr)
376 ipaddress.IPv6Address(addr)
396 ipaddress.IPv6Address(addr)
416 ipaddress.IPv6Address(addr)
425 ipaddress.IPv6Address(addr)
453 ipaddress.IPv6Address(addr)
469 ipaddress.IPv6Address(addr)
484 ipaddress.IPv6Address(addr)
512 ipaddress.IPv6Address(addr)
532 ipaddress.IPv6Address(addr)
638 factory = ipaddress.IPv4Interface
642 factory = ipaddress.IPv4Network
682 ipaddress.IPv4Network('10.0.0.0/30').supernet_of(
683 ipaddress.IPv6Network('::1/128'))
685 ipaddress.IPv6Network('::1/128').supernet_of(
686 ipaddress.IPv4Network('10.0.0.0/30'))
688 ipaddress.IPv4Network('10.0.0.0/30').subnet_of(
689 ipaddress.IPv6Network('::1/128'))
691 ipaddress.IPv6Network('::1/128').subnet_of(
692 ipaddress.IPv4Network('10.0.0.0/30'))
797 factory = ipaddress.IPv6Interface
801 factory = ipaddress.IPv6Network
857 self.assertFactoryError(ipaddress.ip_address, "address")
860 self.assertFactoryError(ipaddress.ip_interface, "interface")
863 self.assertFactoryError(ipaddress.ip_network, "network")
868 v4addr = ipaddress.IPv4Address(1)
869 v4net = ipaddress.IPv4Network(1)
870 v4intf = ipaddress.IPv4Interface(1)
871 v6addr = ipaddress.IPv6Address(1)
872 v6net = ipaddress.IPv6Network(1)
873 v6intf = ipaddress.IPv6Interface(1)
874 v6addr_scoped = ipaddress.IPv6Address('::1%scope')
875 v6net_scoped= ipaddress.IPv6Network('::1%scope')
876 v6intf_scoped= ipaddress.IPv6Interface('::1%scope')
888 v4addr2 = ipaddress.IPv4Address(2)
889 v4net2 = ipaddress.IPv4Network(2)
890 v4intf2 = ipaddress.IPv4Interface(2)
891 v6addr2 = ipaddress.IPv6Address(2)
892 v6net2 = ipaddress.IPv6Network(2)
893 v6intf2 = ipaddress.IPv6Interface(2)
894 v6addr2_scoped = ipaddress.IPv6Address('::2%scope')
895 v6net2_scoped = ipaddress.IPv6Network('::2%scope')
896 v6intf2_scoped = ipaddress.IPv6Interface('::2%scope')
1005 key=ipaddress.get_mixed_type_key))
1008 key=ipaddress.get_mixed_type_key))
1011 key=ipaddress.get_mixed_type_key))
1014 key=ipaddress.get_mixed_type_key))
1015 self.assertEqual(NotImplemented, ipaddress.get_mixed_type_key(object))
1019 v4addr = ipaddress.ip_address('1.1.1.1')
1020 v4net = ipaddress.ip_network('1.1.1.1')
1021 v6addr = ipaddress.ip_address('::1')
1022 v6net = ipaddress.ip_network('::1')
1023 v6addr_scoped = ipaddress.ip_address('::1%scope')
1024 v6net_scoped = ipaddress.ip_network('::1%scope')
1050 self.ipv4_address = ipaddress.IPv4Address('1.2.3.4')
1051 self.ipv4_interface = ipaddress.IPv4Interface('1.2.3.4/24')
1052 self.ipv4_network = ipaddress.IPv4Network('1.2.3.0/24')
1054 self.ipv6_address = ipaddress.IPv6Interface(
1056 self.ipv6_interface = ipaddress.IPv6Interface(
1058 self.ipv6_network = ipaddress.IPv6Network('2001:658:22a:cafe::/64')
1059 self.ipv6_scoped_address = ipaddress.IPv6Interface(
1061 self.ipv6_scoped_interface = ipaddress.IPv6Interface(
1063 self.ipv6_scoped_network = ipaddress.IPv6Network('2001:658:22a:cafe::%scope/64')
1067 repr(ipaddress.IPv4Interface('1.2.3.4')))
1069 repr(ipaddress.IPv6Interface('::1')))
1071 repr(ipaddress.IPv6Interface('::1%scope')))
1076 ip = ipaddress.IPv4Address('192.0.2.1')
1077 net = ipaddress.IPv4Network('192.0.2.1/32')
1078 self.assertEqual(ipaddress.IPv4Network(('192.0.2.1', 32)), net)
1079 self.assertEqual(ipaddress.IPv4Network((ip, 32)), net)
1080 self.assertEqual(ipaddress.IPv4Network((3221225985, 32)), net)
1081 self.assertEqual(ipaddress.IPv4Network(('192.0.2.1',
1083 self.assertEqual(ipaddress.IPv4Network((ip,
1085 self.assertEqual(ipaddress.IPv4Network((3221225985,
1089 ipaddress.IPv4Network(('192.0.2.1', 24))
1091 ipaddress.IPv4Network((ip, 24))
1093 ipaddress.IPv4Network((3221225985, 24))
1095 ipaddress.IPv4Network(('192.0.2.1', '255.255.255.0'))
1097 ipaddress.IPv4Network((ip, '255.255.255.0'))
1099 ipaddress.IPv4Network((3221225985, '255.255.255.0'))
1101 net = ipaddress.IPv4Network('192.0.2.0/24')
1102 self.assertEqual(ipaddress.IPv4Network(('192.0.2.1', 24),
1104 self.assertEqual(ipaddress.IPv4Network((ip, 24),
1106 self.assertEqual(ipaddress.IPv4Network((3221225985, 24),
1108 self.assertEqual(ipaddress.IPv4Network(('192.0.2.1',
1111 self.assertEqual(ipaddress.IPv4Network((ip,
1114 self.assertEqual(ipaddress.IPv4Network((3221225985,
1119 ip = ipaddress.IPv4Address('192.0.2.0')
1120 net = ipaddress.IPv4Network('192.0.2.0/24')
1121 self.assertEqual(ipaddress.IPv4Network(('192.0.2.0',
1123 self.assertEqual(ipaddress.IPv4Network((ip,
1125 self.assertEqual(ipaddress.IPv4Network((3221225984,
1127 self.assertEqual(ipaddress.IPv4Network(('192.0.2.0', 24)), net)
1128 self.assertEqual(ipaddress.IPv4Network((ip, 24)), net)
1129 self.assertEqual(ipaddress.IPv4Network((3221225984, 24)), net)
1131 self.assertEqual(ipaddress.IPv4Interface(('192.0.2.1', 24)),
1132 ipaddress.IPv4Interface('192.0.2.1/24'))
1133 self.assertEqual(ipaddress.IPv4Interface((3221225985, 24)),
1134 ipaddress.IPv4Interface('192.0.2.1/24'))
1139 ip = ipaddress.IPv6Address('2001:db8::')
1140 net = ipaddress.IPv6Network('2001:db8::/128')
1141 self.assertEqual(ipaddress.IPv6Network(('2001:db8::', '128')),
1143 self.assertEqual(ipaddress.IPv6Network(
1146 self.assertEqual(ipaddress.IPv6Network((ip, '128')),
1148 ip = ipaddress.IPv6Address('2001:db8::')
1149 net = ipaddress.IPv6Network('2001:db8::/96')
1150 self.assertEqual(ipaddress.IPv6Network(('2001:db8::', '96')),
1152 self.assertEqual(ipaddress.IPv6Network(
1155 self.assertEqual(ipaddress.IPv6Network((ip, '96')),
1158 ip_scoped = ipaddress.IPv6Address('2001:db8::%scope')
1161 ip = ipaddress.IPv6Address('2001:db8::1')
1163 ipaddress.IPv6Network(('2001:db8::1', 96))
1165 ipaddress.IPv6Network((
1168 ipaddress.IPv6Network((ip, 96))
1170 net = ipaddress.IPv6Network('2001:db8::/96')
1171 self.assertEqual(ipaddress.IPv6Network(('2001:db8::1', 96),
1174 self.assertEqual(ipaddress.IPv6Network(
1178 self.assertEqual(ipaddress.IPv6Network((ip, 96), strict=False),
1182 self.assertEqual(ipaddress.IPv6Interface(('2001:db8::1', '96')),
1183 ipaddress.IPv6Interface('2001:db8::1/96'))
1184 self.assertEqual(ipaddress.IPv6Interface(
1186 ipaddress.IPv6Interface('2001:db8::1/96'))
1188 ip_scoped = ipaddress.IPv6Address('2001:db8::1%scope')
1190 ipaddress.IPv6Network(('2001:db8::1%scope', 96))
1192 ipaddress.IPv6Network((ip_scoped, 96))
1197 self.assertEqual(ipaddress.IPv4Address('1.1.1.1') + 255,
1198 ipaddress.IPv4Address('1.1.2.0'))
1199 self.assertEqual(ipaddress.IPv4Address('1.1.1.1') - 256,
1200 ipaddress.IPv4Address('1.1.0.1'))
1201 self.assertEqual(ipaddress.IPv6Address('::1') + (2**16 - 2),
1202 ipaddress.IPv6Address('::ffff'))
1203 self.assertEqual(ipaddress.IPv6Address('::ffff') - (2**16 - 2),
1204 ipaddress.IPv6Address('::1'))
1205 self.assertNotEqual(ipaddress.IPv6Address('::1%scope') + (2**16 - 2),
1206 ipaddress.IPv6Address('::ffff%scope'))
1207 self.assertNotEqual(ipaddress.IPv6Address('::ffff%scope') - (2**16 - 2),
1208 ipaddress.IPv6Address('::1%scope'))
1211 self.assertRaises(ValueError, ipaddress.v4_int_to_packed, -1)
1212 self.assertRaises(ValueError, ipaddress.v4_int_to_packed,
1213 2 ** ipaddress.IPV4LENGTH)
1214 self.assertRaises(ValueError, ipaddress.v6_int_to_packed, -1)
1215 self.assertRaises(ValueError, ipaddress.v6_int_to_packed,
1216 2 ** ipaddress.IPV6LENGTH)
1219 ip1 = ipaddress.IPv4Address('10.10.10.10')
1220 ip2 = ipaddress.IPv4Address('10.10.10.11')
1221 ip3 = ipaddress.IPv4Address('10.10.10.12')
1222 self.assertEqual(list(ipaddress._find_address_range([ip1])),
1224 self.assertEqual(list(ipaddress._find_address_range([ip1, ip3])),
1226 self.assertEqual(list(ipaddress._find_address_range([ip1, ip2, ip3])),
1228 self.assertEqual(128, ipaddress._count_righthand_zero_bits(0, 128))
1250 ipaddress.IPv4Interface(16909060)._ip)
1252 ipv4 = ipaddress.ip_network('1.2.3.4')
1253 ipv6 = ipaddress.ip_network('2001:658:22a:cafe:200:0:0:1')
1254 ipv6_scoped = ipaddress.ip_network('2001:658:22a:cafe:200:0:0:1%scope')
1255 self.assertEqual(ipv4, ipaddress.ip_network(int(ipv4.network_address)))
1256 self.assertEqual(ipv6, ipaddress.ip_network(int(ipv6.network_address)))
1257 self.assertNotEqual(ipv6_scoped, ipaddress.ip_network(int(ipv6_scoped.network_address)))
1261 ipaddress.IPv6Interface(v6_int)._ip)
1263 ipaddress.IPv6Interface(v6_int)._ip)
1265 self.assertEqual(ipaddress.ip_network(self.ipv4_address._ip).version,
1267 self.assertEqual(ipaddress.ip_network(self.ipv6_address._ip).version,
1269 self.assertEqual(ipaddress.ip_network(self.ipv6_scoped_address._ip).version,
1273 address = ipaddress.ip_address
1275 ipaddress.ip_interface(b'\x01\x02\x03\x04')._ip)
1279 ipaddress.ip_interface(
1326 ipv4_zero_netmask = ipaddress.IPv4Interface('1.2.3.4/0')
1330 ipv6_zero_netmask = ipaddress.IPv6Interface('::1/0')
1334 ipv6_scoped_zero_netmask = ipaddress.IPv6Interface('::1%scope/0')
1339 net = ipaddress.IPv4Network('127.0.0.0/0.0.0.255')
1366 ipaddress.IPv4Interface('0.0.0.0/0').network.supernet(),
1367 ipaddress.IPv4Network('0.0.0.0/0'))
1372 self.assertEqual(ipaddress.IPv6Interface('::0/0').network.supernet(),
1373 ipaddress.IPv6Network('::0/0'))
1414 self.assertEqual(ipaddress.IPv4Address('1.2.3.1'), hosts[0])
1415 self.assertEqual(ipaddress.IPv4Address('1.2.3.254'), hosts[-1])
1417 ipv6_network = ipaddress.IPv6Network('2001:658:22a:cafe::/120')
1420 self.assertEqual(ipaddress.IPv6Address('2001:658:22a:cafe::1'), hosts[0])
1421 self.assertEqual(ipaddress.IPv6Address('2001:658:22a:cafe::ff'), hosts[-1])
1423 ipv6_scoped_network = ipaddress.IPv6Network('2001:658:22a:cafe::%scope/120')
1426 self.assertEqual(ipaddress.IPv6Address('2001:658:22a:cafe::1'), hosts[0])
1427 self.assertEqual(ipaddress.IPv6Address('2001:658:22a:cafe::ff'), hosts[-1])
1430 addrs = [ipaddress.IPv4Address('2.0.0.0'),
1431 ipaddress.IPv4Address('2.0.0.1')]
1434 self.assertEqual(addrs, list(ipaddress.ip_network(str_args).hosts()))
1435 self.assertEqual(addrs, list(ipaddress.ip_network(tpl_args).hosts()))
1436 self.assertEqual(list(ipaddress.ip_network(str_args).hosts()),
1437 list(ipaddress.ip_network(tpl_args).hosts()))
1440 addrs = [ipaddress.IPv4Address('1.2.3.4')]
1443 self.assertEqual(addrs, list(ipaddress.ip_network(str_args).hosts()))
1444 self.assertEqual(addrs, list(ipaddress.ip_network(tpl_args).hosts()))
1445 self.assertEqual(list(ipaddress.ip_network(str_args).hosts()),
1446 list(ipaddress.ip_network(tpl_args).hosts()))
1448 addrs = [ipaddress.IPv6Address('2001:658:22a:cafe::'),
1449 ipaddress.IPv6Address('2001:658:22a:cafe::1')]
1452 self.assertEqual(addrs, list(ipaddress.ip_network(str_args).hosts()))
1453 self.assertEqual(addrs, list(ipaddress.ip_network(tpl_args).hosts()))
1454 self.assertEqual(list(ipaddress.ip_network(str_args).hosts()),
1455 list(ipaddress.ip_network(tpl_args).hosts()))
1457 addrs = [ipaddress.IPv6Address('2001:658:22a:cafe::1'), ]
1460 self.assertEqual(addrs, list(ipaddress.ip_network(str_args).hosts()))
1461 self.assertEqual(addrs, list(ipaddress.ip_network(tpl_args).hosts()))
1462 self.assertEqual(list(ipaddress.ip_network(str_args).hosts()),
1463 list(ipaddress.ip_network(tpl_args).hosts()))
1501 ip = ipaddress.IPv4Network('1.2.3.4/32')
1508 ip = ipaddress.IPv6Network('::1/128')
1514 ip_scoped = ipaddress.IPv6Network('::1%scope/128')
1542 ipv6_network = ipaddress.IPv6Network('2001:658:22a:cafe::/120')
1608 self.assertIn(ipaddress.IPv4Interface('1.2.3.128/25'),
1610 self.assertNotIn(ipaddress.IPv4Interface('1.2.4.1/24'),
1613 addr1 = ipaddress.IPv4Address('1.2.3.37')
1617 self.assertFalse(ipaddress.IPv4Network('1.1.0.0/16').__contains__(
1618 ipaddress.IPv4Network('1.0.0.0/15')))
1633 addr = ipaddress.IPv4Network('172.31.255.128/255.255.255.240')
1644 ipaddress.IPv4Interface('1.2.3.4/24'))
1646 ipaddress.IPv4Interface('1.2.3.4/23'))
1648 ipaddress.IPv6Interface('::1.2.3.4/24'))
1650 ipaddress.IPv6Interface('::1.2.3.4%scope/24'))
1656 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/64'))
1658 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/63'))
1660 ipaddress.IPv4Interface('1.2.3.4/23'))
1666 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1%scope/64'))
1668 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1%scope/63'))
1670 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/64'))
1672 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/63'))
1674 ipaddress.IPv4Interface('1.2.3.4/23'))
1681 ipaddress.IPv4Interface('1.2.3.4/24'))
1683 ipaddress.IPv4Interface('1.2.3.4/23'))
1685 ipaddress.IPv6Interface('::1.2.3.4/24'))
1687 ipaddress.IPv6Interface('::1.2.3.4%scope/24'))
1693 ipaddress.IPv4Address('1.2.3.5'))
1699 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/64'))
1701 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/63'))
1703 ipaddress.IPv4Interface('1.2.3.4/23'))
1709 ipaddress.IPv4Address('1.2.3.4'))
1715 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1%scope/64'))
1717 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1%scope/63'))
1719 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/64'))
1721 ipaddress.IPv6Interface('2001:658:22a:cafe:200::1/63'))
1723 ipaddress.IPv4Interface('1.2.3.4/23'))
1729 ipaddress.IPv4Address('1.2.3.4'))
1735 self.assertEqual(str(ipaddress.IPv4Interface(
1739 self.assertEqual(str(ipaddress.IPv6Interface('::1/128')),
1741 self.assertEqual(str(ipaddress.IPv6Interface('::1%scope/128')),
1745 self.assertEqual(str(ipaddress.IPv4Interface('1.2.3.4/0.0.0.0')),
1750 ip1 = ipaddress.IPv4Address('1.1.1.0')
1751 ip2 = ipaddress.IPv4Address('1.1.1.1')
1752 ip3 = ipaddress.IPv4Address('1.1.1.2')
1753 ip4 = ipaddress.IPv4Address('1.1.1.3')
1754 ip5 = ipaddress.IPv4Address('1.1.1.4')
1755 ip6 = ipaddress.IPv4Address('1.1.1.0')
1757 collapsed = ipaddress.collapse_addresses(
1760 [ipaddress.IPv4Network('1.1.1.0/30'),
1761 ipaddress.IPv4Network('1.1.1.4/32')])
1764 ip1 = ipaddress.IPv4Address('1.1.1.0')
1765 ip2 = ipaddress.IPv4Address('1.1.1.1')
1766 ip3 = ipaddress.IPv4Address('1.1.1.2')
1767 ip4 = ipaddress.IPv4Address('1.1.1.3')
1771 collapsed = ipaddress.collapse_addresses([ip1, ip2, ip3, ip4])
1773 [ipaddress.IPv4Network('1.1.1.0/30')])
1776 ip1 = ipaddress.IPv4Network('1.1.0.0/24')
1777 ip2 = ipaddress.IPv4Network('1.1.1.0/24')
1778 ip3 = ipaddress.IPv4Network('1.1.2.0/24')
1779 ip4 = ipaddress.IPv4Network('1.1.3.0/24')
1780 ip5 = ipaddress.IPv4Network('1.1.4.0/24')
1783 ip6 = ipaddress.IPv4Network('1.1.0.0/22')
1785 collapsed = ipaddress.collapse_addresses([ip1, ip2, ip3, ip4, ip5,
1788 [ipaddress.IPv4Network('1.1.0.0/22'),
1789 ipaddress.IPv4Network('1.1.4.0/24')])
1792 collapsed = ipaddress.collapse_addresses([ip1, ip2])
1794 [ipaddress.IPv4Network('1.1.0.0/23')])
1797 ip_same1 = ip_same2 = ipaddress.IPv4Network('1.1.1.1/32')
1798 self.assertEqual(list(ipaddress.collapse_addresses(
1803 ip_same1 = ip_same2 = ipaddress.IPv4Address('1.1.1.1')
1804 self.assertEqual(list(ipaddress.collapse_addresses(
1806 [ipaddress.ip_network('1.1.1.1/32')])
1807 ip1 = ipaddress.IPv6Network('2001::/100')
1808 ip2 = ipaddress.IPv6Network('2001::/120')
1809 ip3 = ipaddress.IPv6Network('2001::/96')
1811 collapsed = ipaddress.collapse_addresses([ip1, ip2, ip3])
1814 ip1 = ipaddress.IPv6Network('2001::%scope/100')
1815 ip2 = ipaddress.IPv6Network('2001::%scope/120')
1816 ip3 = ipaddress.IPv6Network('2001::%scope/96')
1818 collapsed = ipaddress.collapse_addresses([ip1, ip2, ip3])
1823 (ipaddress.ip_address('1.1.1.1'),
1824 ipaddress.ip_address('::1')),
1825 (ipaddress.IPv4Network('1.1.0.0/24'),
1826 ipaddress.IPv6Network('2001::/120')),
1827 (ipaddress.IPv4Network('1.1.0.0/32'),
1828 ipaddress.IPv6Network('2001::/128')),
1831 self.assertRaises(TypeError, ipaddress.collapse_addresses,
1835 (ipaddress.ip_address('1.1.1.1'),
1836 ipaddress.ip_address('::1%scope')),
1837 (ipaddress.IPv4Network('1.1.0.0/24'),
1838 ipaddress.IPv6Network('2001::%scope/120')),
1839 (ipaddress.IPv4Network('1.1.0.0/32'),
1840 ipaddress.IPv6Network('2001::%scope/128')),
1843 self.assertRaises(TypeError, ipaddress.collapse_addresses,
1849 summarize = ipaddress.summarize_address_range
1850 ip1 = ipaddress.ip_address('1.1.1.0')
1851 ip2 = ipaddress.ip_address('1.1.1.255')
1854 class IPv7Address(ipaddress.IPv6Address):
1864 summarize(ip1, ipaddress.IPv6Address('::1')))
1866 summarize(ip1, ipaddress.IPv6Address('::1%scope')))
1869 ipaddress.ip_network('1.1.1.0/24'))
1871 ip2 = ipaddress.ip_address('1.1.1.8')
1873 [ipaddress.ip_network('1.1.1.0/29'),
1874 ipaddress.ip_network('1.1.1.8')])
1876 ip1 = ipaddress.IPv4Address(0)
1877 ip2 = ipaddress.IPv4Address(ipaddress.IPv4Address._ALL_ONES)
1878 self.assertEqual([ipaddress.IPv4Network('0.0.0.0/0')],
1881 ip1 = ipaddress.ip_address('1::')
1882 ip2 = ipaddress.ip_address('1:ffff:ffff:ffff:ffff:ffff:ffff:ffff')
1885 ipaddress.ip_network('1::/16'))
1887 ip2 = ipaddress.ip_address('2::')
1889 [ipaddress.ip_network('1::/16'),
1890 ipaddress.ip_network('2::/128')])
1892 ip1 = ipaddress.ip_address('1::%scope')
1893 ip2 = ipaddress.ip_address('1:ffff:ffff:ffff:ffff:ffff:ffff:ffff%scope')
1896 ipaddress.ip_network('1::/16'))
1898 ip2 = ipaddress.ip_address('2::%scope')
1900 [ipaddress.ip_network('1::/16'),
1901 ipaddress.ip_network('2::/128')])
1905 summarize(ipaddress.ip_address('1.1.1.0'),
1906 ipaddress.ip_address('1.1.0.0')))
1909 summarize(ipaddress.ip_network('1.1.1.0'),
1910 ipaddress.ip_network('1.1.0.0')))
1912 summarize(ipaddress.ip_network('1.1.1.0'),
1913 ipaddress.ip_network('1.1.0.0')))
1916 summarize(ipaddress.ip_address('::'),
1917 ipaddress.ip_network('1.1.0.0')))
1920 self.assertTrue(ipaddress.ip_address('1.1.1.1') <=
1921 ipaddress.ip_address('1.1.1.1'))
1922 self.assertTrue(ipaddress.ip_address('1.1.1.1') <=
1923 ipaddress.ip_address('1.1.1.2'))
1924 self.assertTrue(ipaddress.ip_address('::1') <=
1925 ipaddress.ip_address('::1'))
1926 self.assertTrue(ipaddress.ip_address('::1') <=
1927 ipaddress.ip_address('::2'))
1928 self.assertTrue(ipaddress.ip_address('::1%scope') <=
1929 ipaddress.ip_address('::1%scope'))
1930 self.assertTrue(ipaddress.ip_address('::1%scope') <=
1931 ipaddress.ip_address('::2%scope'))
1934 self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') ==
1935 ipaddress.ip_interface('1.1.1.1/24'))
1936 self.assertTrue(ipaddress.ip_interface('1.1.1.1/16') <
1937 ipaddress.ip_interface('1.1.1.1/24'))
1938 self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') <
1939 ipaddress.ip_interface('1.1.1.2/24'))
1940 self.assertTrue(ipaddress.ip_interface('1.1.1.2/16') <
1941 ipaddress.ip_interface('1.1.1.1/24'))
1942 self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') >
1943 ipaddress.ip_interface('1.1.1.1/16'))
1944 self.assertTrue(ipaddress.ip_interface('1.1.1.2/24') >
1945 ipaddress.ip_interface('1.1.1.1/24'))
1946 self.assertTrue(ipaddress.ip_interface('1.1.1.1/24') >
1947 ipaddress.ip_interface('1.1.1.2/16'))
1949 self.assertTrue(ipaddress.ip_interface('::1/64') ==
1950 ipaddress.ip_interface('::1/64'))
1951 self.assertTrue(ipaddress.ip_interface('::1/64') <
1952 ipaddress.ip_interface('::1/80'))
1953 self.assertTrue(ipaddress.ip_interface('::1/64') <
1954 ipaddress.ip_interface('::2/64'))
1955 self.assertTrue(ipaddress.ip_interface('::2/48') <
1956 ipaddress.ip_interface('::1/64'))
1957 self.assertTrue(ipaddress.ip_interface('::1/80') >
1958 ipaddress.ip_interface('::1/64'))
1959 self.assertTrue(ipaddress.ip_interface('::2/64') >
1960 ipaddress.ip_interface('::1/64'))
1961 self.assertTrue(ipaddress.ip_interface('::1/64') >
1962 ipaddress.ip_interface('::2/48'))
1964 self.assertTrue(ipaddress.ip_interface('::1%scope/64') ==
1965 ipaddress.ip_interface('::1%scope/64'))
1966 self.assertTrue(ipaddress.ip_interface('::1%scope/64') <
1967 ipaddress.ip_interface('::1%scope/80'))
1968 self.assertTrue(ipaddress.ip_interface('::1%scope/64') <
1969 ipaddress.ip_interface('::2%scope/64'))
1970 self.assertTrue(ipaddress.ip_interface('::2%scope/48') <
1971 ipaddress.ip_interface('::1%scope/64'))
1972 self.assertTrue(ipaddress.ip_interface('::1%scope/80') >
1973 ipaddress.ip_interface('::1%scope/64'))
1974 self.assertTrue(ipaddress.ip_interface('::2%scope/64') >
1975 ipaddress.ip_interface('::1%scope/64'))
1976 self.assertTrue(ipaddress.ip_interface('::1%scope/64') >
1977 ipaddress.ip_interface('::2%scope/48'))
1980 self.assertFalse(ipaddress.ip_interface('::1%scope/64') ==
1981 ipaddress.ip_interface('::1/64'))
1982 self.assertTrue(ipaddress.ip_interface('::1%scope/64') <
1983 ipaddress.ip_interface('::1/80'))
1984 self.assertTrue(ipaddress.ip_interface('::1%scope/64') <
1985 ipaddress.ip_interface('::2/64'))
1986 self.assertTrue(ipaddress.ip_interface('::2%scope/48') <
1987 ipaddress.ip_interface('::1/64'))
1988 self.assertTrue(ipaddress.ip_interface('::1%scope/80') >
1989 ipaddress.ip_interface('::1/64'))
1990 self.assertTrue(ipaddress.ip_interface('::2%scope/64') >
1991 ipaddress.ip_interface('::1/64'))
1992 self.assertTrue(ipaddress.ip_interface('::1%scope/64') >
1993 ipaddress.ip_interface('::2/48'))
1995 self.assertFalse(ipaddress.ip_interface('::1/64') ==
1996 ipaddress.ip_interface('::1%scope/64'))
1997 self.assertTrue(ipaddress.ip_interface('::1/64') <
1998 ipaddress.ip_interface('::1%scope/80'))
1999 self.assertTrue(ipaddress.ip_interface('::1/64') <
2000 ipaddress.ip_interface('::2%scope/64'))
2001 self.assertTrue(ipaddress.ip_interface('::2/48') <
2002 ipaddress.ip_interface('::1%scope/64'))
2003 self.assertTrue(ipaddress.ip_interface('::1/80') >
2004 ipaddress.ip_interface('::1%scope/64'))
2005 self.assertTrue(ipaddress.ip_interface('::2/64') >
2006 ipaddress.ip_interface('::1%scope/64'))
2007 self.assertTrue(ipaddress.ip_interface('::1/64') >
2008 ipaddress.ip_interface('::2%scope/48'))
2012 ip1 = ipaddress.IPv4Network('1.1.1.0/24')
2013 ip2 = ipaddress.IPv4Network('1.1.1.0/32')
2014 ip3 = ipaddress.IPv4Network('1.1.2.0/24')
2029 ip1 = ipaddress.IPv6Network('2001:2000::/96')
2030 ip2 = ipaddress.IPv6Network('2001:2001::/96')
2031 ip3 = ipaddress.IPv6Network('2001:ffff:2000::/96')
2043 ipv6 = ipaddress.IPv6Interface('::/0')
2044 ipv4 = ipaddress.IPv4Interface('0.0.0.0/0')
2051 ip1 = ipaddress.ip_network('10.1.2.128/25')
2054 ip2 = ipaddress.ip_network('10.1.3.0/24')
2059 ip3 = ipaddress.ip_network('10.1.3.0/25')
2066 ip1 = ipaddress.ip_network('10.10.10.0/31')
2067 ip2 = ipaddress.ip_network('10.10.10.0')
2068 ip3 = ipaddress.ip_network('10.10.10.2/31')
2069 ip4 = ipaddress.ip_network('10.10.10.2')
2077 self.assertIs(ip1.__lt__(ipaddress.ip_address('10.10.10.0')),
2079 self.assertIs(ip2.__lt__(ipaddress.ip_address('10.10.10.0')),
2083 self.assertTrue(ipaddress.ip_network('1.1.1.1') <=
2084 ipaddress.ip_network('1.1.1.1'))
2085 self.assertTrue(ipaddress.ip_network('1.1.1.1') <=
2086 ipaddress.ip_network('1.1.1.2'))
2087 self.assertFalse(ipaddress.ip_network('1.1.1.2') <=
2088 ipaddress.ip_network('1.1.1.1'))
2090 self.assertTrue(ipaddress.ip_network('::1') <=
2091 ipaddress.ip_network('::1'))
2092 self.assertTrue(ipaddress.ip_network('::1') <=
2093 ipaddress.ip_network('::2'))
2094 self.assertFalse(ipaddress.ip_network('::2') <=
2095 ipaddress.ip_network('::1'))
2098 self.assertRaises(ValueError, ipaddress.ip_network, '192.168.1.1/24')
2099 self.assertRaises(ValueError, ipaddress.ip_network, '::1/120')
2100 self.assertRaises(ValueError, ipaddress.ip_network, '::1%scope/120')
2103 other = ipaddress.IPv4Network('1.2.3.0/30')
2104 other2 = ipaddress.IPv4Network('1.2.2.0/24')
2105 other3 = ipaddress.IPv4Network('1.2.2.64/26')
2112 ipv4 = ipaddress.IPv4Interface(ipv4_string)
2113 v4compat_ipv6 = ipaddress.IPv6Interface('::%s' % ipv4_string)
2115 v4mapped_ipv6 = ipaddress.IPv6Interface('::ffff:%s' % ipv4_string)
2117 self.assertRaises(ipaddress.AddressValueError, ipaddress.IPv6Interface,
2123 self.assertEqual(ipaddress.ip_address('::FFFF:192.0.2.1'),
2124 ipaddress.ip_address('::FFFF:c000:201'))
2126 self.assertEqual(ipaddress.ip_address('FFFF::192.0.2.1'),
2127 ipaddress.ip_address('FFFF::c000:201'))
2129 self.assertEqual(ipaddress.ip_address('::FFFF:192.0.2.1%scope'),
2130 ipaddress.ip_address('::FFFF:c000:201%scope'))
2131 self.assertEqual(ipaddress.ip_address('FFFF::192.0.2.1%scope'),
2132 ipaddress.ip_address('FFFF::c000:201%scope'))
2133 self.assertNotEqual(ipaddress.ip_address('::FFFF:192.0.2.1%scope'),
2134 ipaddress.ip_address('::FFFF:c000:201'))
2135 self.assertNotEqual(ipaddress.ip_address('FFFF::192.0.2.1%scope'),
2136 ipaddress.ip_address('FFFF::c000:201'))
2137 self.assertNotEqual(ipaddress.ip_address('::FFFF:192.0.2.1'),
2138 ipaddress.ip_address('::FFFF:c000:201%scope'))
2139 self.assertNotEqual(ipaddress.ip_address('FFFF::192.0.2.1'),
2140 ipaddress.ip_address('FFFF::c000:201%scope'))
2155 self.assertEqual(ipaddress.IPv4Interface('255.254.253.252').packed,
2160 self.assertEqual(ipaddress.IPv6Interface('ffff:2:3:4:ffff::').packed,
2163 self.assertEqual(ipaddress.IPv6Interface('::1:0:0:0:0').packed,
2168 self.assertEqual(ipaddress.IPv6Interface('ffff:2:3:4:ffff::%scope').packed,
2171 self.assertEqual(ipaddress.IPv6Interface('::1:0:0:0:0%scope').packed,
2175 ipv4net = ipaddress.ip_network('1.2.3.4')
2176 ipv4addr = ipaddress.ip_address('1.2.3.4')
2177 ipv6net = ipaddress.ip_network('::1.2.3.4')
2178 ipv6addr = ipaddress.ip_address('::1.2.3.4')
2179 self.assertEqual(ipaddress.IPv4Network, type(ipv4net))
2180 self.assertEqual(ipaddress.IPv4Address, type(ipv4addr))
2181 self.assertEqual(ipaddress.IPv6Network, type(ipv6net))
2182 self.assertEqual(ipaddress.IPv6Address, type(ipv6addr))
2186 self.assertEqual(True, ipaddress.ip_interface(
2188 self.assertEqual(False, ipaddress.ip_network('240.0.0.0').is_multicast)
2189 self.assertEqual(True, ipaddress.ip_network('240.0.0.0').is_reserved)
2191 self.assertEqual(True, ipaddress.ip_interface(
2193 self.assertEqual(False, ipaddress.ip_network('192.169.0.0').is_private)
2194 self.assertEqual(True, ipaddress.ip_network(
2196 self.assertEqual(False, ipaddress.ip_network('11.0.0.0').is_private)
2197 self.assertEqual(False, ipaddress.ip_network('11.0.0.0').is_reserved)
2198 self.assertEqual(True, ipaddress.ip_network(
2200 self.assertEqual(False, ipaddress.ip_network('172.32.0.0').is_private)
2202 ipaddress.ip_network('169.254.1.0/24').is_link_local)
2205 ipaddress.ip_interface(
2208 ipaddress.ip_interface(
2212 ipaddress.ip_network(
2214 self.assertEqual(True, ipaddress.ip_network(
2216 self.assertEqual(False, ipaddress.ip_network('128.0.0.0').is_loopback)
2218 ipaddress.ip_network('100.64.0.0/10').is_private)
2219 self.assertEqual(False, ipaddress.ip_network('100.64.0.0/10').is_global)
2222 ipaddress.ip_network('192.0.2.128/25').is_private)
2224 ipaddress.ip_network('192.0.3.0/24').is_global)
2227 self.assertEqual(True, ipaddress.ip_address('0.0.0.0').is_unspecified)
2228 self.assertEqual(True, ipaddress.ip_address('224.1.1.1').is_multicast)
2229 self.assertEqual(False, ipaddress.ip_address('240.0.0.0').is_multicast)
2230 self.assertEqual(True, ipaddress.ip_address('240.0.0.1').is_reserved)
2232 ipaddress.ip_address('239.255.255.255').is_reserved)
2234 self.assertEqual(True, ipaddress.ip_address('192.168.1.1').is_private)
2235 self.assertEqual(False, ipaddress.ip_address('192.169.0.0').is_private)
2236 self.assertEqual(True, ipaddress.ip_address(
2238 self.assertEqual(False, ipaddress.ip_address('11.0.0.0').is_private)
2239 self.assertEqual(True, ipaddress.ip_address(
2241 self.assertEqual(False, ipaddress.ip_address('172.32.0.0').is_private)
2244 ipaddress.ip_address('169.254.100.200').is_link_local)
2246 ipaddress.ip_address('169.255.100.200').is_link_local)
2248 self.assertTrue(ipaddress.ip_address('192.0.7.1').is_global)
2249 self.assertFalse(ipaddress.ip_address('203.0.113.1').is_global)
2252 ipaddress.ip_address('127.100.200.254').is_loopback)
2253 self.assertEqual(True, ipaddress.ip_address('127.42.0.0').is_loopback)
2254 self.assertEqual(False, ipaddress.ip_address('128.0.0.0').is_loopback)
2255 self.assertEqual(True, ipaddress.ip_network('0.0.0.0').is_unspecified)
2259 self.assertEqual(True, ipaddress.ip_network('ffff::').is_multicast)
2260 self.assertEqual(True, ipaddress.ip_network(2**128 - 1).is_multicast)
2261 self.assertEqual(True, ipaddress.ip_network('ff00::').is_multicast)
2262 self.assertEqual(False, ipaddress.ip_network('fdff::').is_multicast)
2264 self.assertEqual(True, ipaddress.ip_network('fecf::').is_site_local)
2265 self.assertEqual(True, ipaddress.ip_network(
2267 self.assertEqual(False, ipaddress.ip_network(
2269 self.assertEqual(False, ipaddress.ip_network('ff00::').is_site_local)
2271 self.assertEqual(True, ipaddress.ip_network('fc00::').is_private)
2272 self.assertEqual(True, ipaddress.ip_network(
2274 self.assertEqual(False, ipaddress.ip_network('fbff:ffff::').is_private)
2275 self.assertEqual(False, ipaddress.ip_network('fe00::').is_private)
2277 self.assertEqual(True, ipaddress.ip_network('fea0::').is_link_local)
2278 self.assertEqual(True, ipaddress.ip_network(
2280 self.assertEqual(False, ipaddress.ip_network(
2282 self.assertEqual(False, ipaddress.ip_network('fec0::').is_link_local)
2284 self.assertEqual(True, ipaddress.ip_interface('0:0::0:01').is_loopback)
2285 self.assertEqual(False, ipaddress.ip_interface('::1/127').is_loopback)
2286 self.assertEqual(False, ipaddress.ip_network('::').is_loopback)
2287 self.assertEqual(False, ipaddress.ip_network('::2').is_loopback)
2289 self.assertEqual(True, ipaddress.ip_network('0::0').is_unspecified)
2290 self.assertEqual(False, ipaddress.ip_network('::1').is_unspecified)
2291 self.assertEqual(False, ipaddress.ip_network('::/127').is_unspecified)
2294 ipaddress.ip_network('2001::1/128').is_private)
2296 ipaddress.ip_network('200::1/128').is_global)
2298 self.assertEqual(True, ipaddress.ip_address('ffff::').is_multicast)
2299 self.assertEqual(True, ipaddress.ip_address(2**128 - 1).is_multicast)
2300 self.assertEqual(True, ipaddress.ip_address('ff00::').is_multicast)
2301 self.assertEqual(False, ipaddress.ip_address('fdff::').is_multicast)
2303 self.assertEqual(True, ipaddress.ip_address('fecf::').is_site_local)
2304 self.assertEqual(True, ipaddress.ip_address(
2306 self.assertEqual(False, ipaddress.ip_address(
2308 self.assertEqual(False, ipaddress.ip_address('ff00::').is_site_local)
2310 self.assertEqual(True, ipaddress.ip_address('fc00::').is_private)
2311 self.assertEqual(True, ipaddress.ip_address(
2313 self.assertEqual(False, ipaddress.ip_address('fbff:ffff::').is_private)
2314 self.assertEqual(False, ipaddress.ip_address('fe00::').is_private)
2316 self.assertEqual(True, ipaddress.ip_address('fea0::').is_link_local)
2317 self.assertEqual(True, ipaddress.ip_address(
2319 self.assertEqual(False, ipaddress.ip_address(
2321 self.assertEqual(False, ipaddress.ip_address('fec0::').is_link_local)
2323 self.assertEqual(True, ipaddress.ip_address('0:0::0:01').is_loopback)
2324 self.assertEqual(True, ipaddress.ip_address('::1').is_loopback)
2325 self.assertEqual(False, ipaddress.ip_address('::2').is_loopback)
2327 self.assertEqual(True, ipaddress.ip_address('0::0').is_unspecified)
2328 self.assertEqual(False, ipaddress.ip_address('::1').is_unspecified)
2331 self.assertEqual(True, ipaddress.ip_address('100::').is_reserved)
2332 self.assertEqual(True, ipaddress.ip_network('4000::1/128').is_reserved)
2336 ipaddress.ip_address('::ffff:192.168.1.1').ipv4_mapped,
2337 ipaddress.ip_address('192.168.1.1'))
2338 self.assertEqual(ipaddress.ip_address('::c0a8:101').ipv4_mapped, None)
2339 self.assertEqual(ipaddress.ip_address('::ffff:c0a8:101').ipv4_mapped,
2340 ipaddress.ip_address('192.168.1.1'))
2344 True, ipaddress.ip_address('::ffff:192.168.1.1').is_private)
2346 False, ipaddress.ip_address('::ffff:172.32.0.0').is_private)
2349 addr1 = ipaddress.ip_network('10.1.1.0/24')
2350 addr2 = ipaddress.ip_network('10.1.1.0/26')
2351 addr3 = ipaddress.ip_network('10.2.1.0/24')
2352 addr4 = ipaddress.ip_address('10.1.1.0')
2353 addr5 = ipaddress.ip_network('2001:db8::0/32')
2354 addr6 = ipaddress.ip_network('10.1.1.5/32')
2356 [ipaddress.ip_network('10.1.1.64/26'),
2357 ipaddress.ip_network('10.1.1.128/25')])
2363 [ipaddress.ip_network('10.1.1.0/30'),
2364 ipaddress.ip_network('10.1.1.4/32'),
2365 ipaddress.ip_network('10.1.1.6/31'),
2366 ipaddress.ip_network('10.1.1.8/29'),
2367 ipaddress.ip_network('10.1.1.16/28'),
2368 ipaddress.ip_network('10.1.1.32/27'),
2369 ipaddress.ip_network('10.1.1.64/26'),
2370 ipaddress.ip_network('10.1.1.128/25')])
2373 self.assertEqual(hash(ipaddress.ip_interface('10.1.1.0/24')),
2374 hash(ipaddress.ip_interface('10.1.1.0/24')))
2375 self.assertEqual(hash(ipaddress.ip_network('10.1.1.0/24')),
2376 hash(ipaddress.ip_network('10.1.1.0/24')))
2377 self.assertEqual(hash(ipaddress.ip_address('10.1.1.0')),
2378 hash(ipaddress.ip_address('10.1.1.0')))
2380 self.assertEqual(hash(ipaddress.ip_address('1.2.3.4')),
2381 hash(ipaddress.ip_address(
2382 int(ipaddress.ip_address('1.2.3.4')._ip))))
2383 ip1 = ipaddress.ip_address('10.1.1.0')
2384 ip2 = ipaddress.ip_address('1::')
2416 addr1 = ipaddress.ip_network('10.1.1.0/24')
2417 addr2 = ipaddress.ip_network(addr1)
2418 addr3 = ipaddress.ip_interface('2001:658:22a:cafe:200::1/64')
2419 addr4 = ipaddress.ip_interface(addr3)
2420 addr5 = ipaddress.IPv4Address('1.1.1.1')
2421 addr6 = ipaddress.IPv6Address('2001:658:22a:cafe:200::1')
2425 self.assertEqual(addr5, ipaddress.IPv4Address(addr5))
2426 self.assertEqual(addr6, ipaddress.IPv6Address(addr6))
2451 self.assertEqual(compressed, str(ipaddress.IPv6Interface(
2455 addr1 = ipaddress.IPv6Interface('2001::1')
2456 addr2 = ipaddress.IPv6Address('2001:0:5ef5:79fd:0:59d:a0e5:ba1')
2457 addr3 = ipaddress.IPv6Network('2001::/96')
2458 addr4 = ipaddress.IPv4Address('192.168.178.1')
2462 ipaddress.IPv6Interface('::1/128').exploded)
2471 addr1 = ipaddress.IPv4Address('127.0.0.1')
2472 addr2 = ipaddress.IPv6Address('2001:db8::1')
2484 self.assertEqual(ipaddress.ip_network(1).version, 4)
2485 self.assertEqual(ipaddress.IPv6Network(1).version, 6)
2510 ipaddress.IPv4Address('1.2.3.255'))
2512 ipaddress.IPv4Address('0.0.0.255'))
2524 ipaddress.IPv6Address('2001:658:22a:cafe::'))
2526 ipaddress.IPv6Address('2001:658:22a:cafe::'))
2530 ipaddress.IPv6Address('2001:658:22a:cafe:ffff:ffff:ffff:ffff'))
2532 ipaddress.IPv6Address('::ffff:ffff:ffff:ffff'))
2535 ipaddress.IPv6Address('2001:658:22a:cafe:ffff:ffff:ffff:ffff'))
2537 ipaddress.IPv6Address('::ffff:ffff:ffff:ffff'))
2547 server = ipaddress.IPv4Address('65.54.227.120')
2548 client = ipaddress.IPv4Address('192.0.2.45')
2551 ipaddress.ip_address(teredo_addr).teredo)
2553 self.assertFalse(ipaddress.ip_address(bad_addr).teredo)
2555 self.assertFalse(ipaddress.ip_address(bad_addr).teredo)
2558 teredo_addr = ipaddress.IPv6Address('2001:0:5ef5:79fd:0:59d:a0e5:ba1')
2559 self.assertEqual((ipaddress.IPv4Address('94.245.121.253'),
2560 ipaddress.IPv4Address('95.26.244.94')),
2564 sixtofouraddr = ipaddress.ip_address('2002:ac1d:2d64::1')
2565 bad_addr = ipaddress.ip_address('2000:ac1d:2d64::1')
2566 self.assertEqual(ipaddress.IPv4Address('172.29.45.100'),
2572 ipv4_address1 = ipaddress.IPv4Interface("1.2.3.4")
2573 ipv4_address2 = ipaddress.IPv4Interface("2.3.4.5")
2578 ipv6_address1 = ipaddress.IPv6Interface("2001:658:22a:cafe:200:0:0:1")
2579 ipv6_address2 = ipaddress.IPv6Interface("2001:658:22a:cafe:200:0:0:2")