NETADDR(1) netaddr NETADDR(1) (NAME) netaddr - netaddr Python CLI <> (IP) (MAC). netaddr : o IPv4 IPv6 o (slicing) IP o (CIDR nmap) o ( ) IP o o IP IANA o DNS o (supernetting) (subnetting) o MAC EUI-64 o IEEE ( OUI IAB) o IPv6 netaddr Diataxis : o (Tutorials) <> netaddr . netaddr . o (How-to guides) <> . o (Reference) <> netaddr ( API <>). netaddr . netaddr . : IP (Tutorial 1: IP Addresses, Subnets and Ranges) netaddr (namespace) . : . (name clashes) (import) . >>> from netaddr import * pprint . >>> import pprint (Basic operations) IPAddress IP . >>> ip = IPAddress('192.0.2.1') >>> ip.version 4 repr() IP . >>> repr(ip) "IPAddress('192.0.2.1')" >>> ip IPAddress('192.0.2.1') IP (string context) . >>> str(ip) '192.0.2.1' >>> '%s' % ip '192.0.2.1' >>> ip.format() # only really useful for IPv6 addresses. '192.0.2.1' (Numerical representation) IP . >>> int(ip) == 3221225985 True >>> hex(ip) '0xc0000201' >>> ip.bin '0b11000000000000000000001000000001' >>> ip.bits() '11000000.00000000.00000010.00000001' >>> ip.words == (192, 0, 2, 1) True (Representing networks and subnets) IPNetwork VLAN CIDR netmask . >>> ip = IPNetwork('192.0.2.1') >>> ip.ip IPAddress('192.0.2.1') >>> ip.network, ip.broadcast (IPAddress('192.0.2.1'), None) >>> ip.netmask, ip.hostmask (IPAddress('255.255.255.255'), IPAddress('0.0.0.0')) >>> ip.size 1 (broadcast) (host route). >>> ip = IPNetwork('192.0.2.0/24') >>> ip.ip IPAddress('192.0.2.0') >>> ip.network, ip.broadcast (IPAddress('192.0.2.0'), IPAddress('192.0.2.255')) >>> ip.netmask, ip.hostmask (IPAddress('255.255.255.0'), IPAddress('0.0.0.255')) >>> ip.size 256 IPNetwork IP IP . >>> ip = IPNetwork('192.0.3.112/22') >>> ip.ip IPAddress('192.0.3.112') >>> ip.network, ip.broadcast (IPAddress('192.0.0.0'), IPAddress('192.0.3.255')) >>> ip.netmask, ip.hostmask (IPAddress('255.255.252.0'), IPAddress('0.0.3.255')) >>> ip.size 1024 IPNetwork : o IP (unsigned integer) o IP IP o (bitmask) CIDR (on-the-fly) . IP CIDR (instantiation) . >>> ip = IPNetwork('0.0.0.0/0') >>> ip IPNetwork('0.0.0.0/0') >>> ip.value = 3221225985 >>> ip IPNetwork('192.0.2.1/0') >>> ip.prefixlen 0 >>> ip.prefixlen = 23 >>> ip IPNetwork('192.0.2.1/23') (prefix length) subnet mask : >>> ip = IPNetwork('192.168.1.0/24') >>> ip.netmask = '255.255.0.0' >>> ip IPNetwork('192.168.1.0/16') >>> ip = IPNetwork('fe80::dead:beef/64') >>> ip.netmask = 'ffff:ffff::' >>> ip IPNetwork('fe80::dead:beef/32') (property) CIDR (host bits) CIDR . >>> ip = IPNetwork('192.0.2.1/23') >>> ip.cidr IPNetwork('192.0.2.0/23') . IP IPAddress . () . >>> ip.ip.bits() '11000000.00000000.00000010.00000001' >>> ip.network.bits() '11000000.00000000.00000010.00000000' >>> ip.netmask.bits() '11111111.11111111.11111110.00000000' >>> ip.broadcast.bits() '11000000.00000000.00000011.11111111' IPv6 . : >>> ip = IPAddress(0, 6) >>> ip IPAddress('::') >>> ip = IPNetwork('fe80::dead:beef/64') >>> str(ip), ip.prefixlen, ip.version ('fe80::dead:beef/64', 64, 6) >>> int(ip.ip) == 338288524927261089654018896845083623151 True >>> hex(ip.ip) '0xfe8000000000000000000000deadbeef' ! >>> ip.ip.bits() '1111111010000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:1101111010101101:1011111011101111' IPv6 . >>> ip.network, ip.broadcast, ip.netmask, ip.hostmask (IPAddress('fe80::'), IPAddress('fe80::ffff:ffff:ffff:ffff'), IPAddress('ffff:ffff:ffff:ffff::'), IPAddress('::ffff:ffff:ffff:ffff')) IPv4 IPv6 IPv6 IPv4 IPv6 . . IPv4 IPv6 >>> IPAddress('192.0.2.15').ipv4() IPAddress('192.0.2.15') >>> ip = IPAddress('192.0.2.15').ipv6() >>> ip IPAddress('::ffff:192.0.2.15') >>> ip.is_ipv4_mapped() True >>> ip.is_ipv4_compat() False >>> IPAddress('192.0.2.15').ipv6(ipv4_compatible=True) IPAddress('::192.0.2.15') >>> IPAddress('192.0.2.15').ipv6(ipv4_compatible=True).is_ipv4_compat() True >>> IPAddress('192.0.2.15').ipv6(True) IPAddress('::192.0.2.15') >>> ip = IPNetwork('192.0.2.1/23') >>> ip.ipv4() IPNetwork('192.0.2.1/23') >>> ip.ipv6() IPNetwork('::ffff:192.0.2.1/119') >>> ip.ipv6(ipv4_compatible=True) IPNetwork('::192.0.2.1/119') IPv6 IPv4 >>> IPNetwork('::ffff:192.0.2.1/119').ipv6() IPNetwork('::ffff:192.0.2.1/119') >>> IPNetwork('::ffff:192.0.2.1/119').ipv6(ipv4_compatible=True) IPNetwork('::192.0.2.1/119') >>> IPNetwork('::ffff:192.0.2.1/119').ipv4() IPNetwork('192.0.2.1/23') >>> IPNetwork('::192.0.2.1/119').ipv4() IPNetwork('192.0.2.1/23') IP IPv4 "" (mapped) "" (compatible) . ( RFC 4291 ). IPNetwork Python IP . . >>> ip = IPNetwork('192.0.2.16/29') IP list() IP IP . >>> ip_list = list(ip) >>> len(ip_list) 8 >>> ip_list [IPAddress('192.0.2.16'), IPAddress('192.0.2.17'), ..., IPAddress('192.0.2.22'), IPAddress('192.0.2.23')] IP . >>> len(ip) 8 IP . >>> ip[0] IPAddress('192.0.2.16') >>> ip[1] IPAddress('192.0.2.17') >>> ip[-1] IPAddress('192.0.2.23') (Slicing) IP . >>> ip[0:4] (generator function) . ! : >>> list(ip[0:4]) [IPAddress('192.0.2.16'), IPAddress('192.0.2.17'), IPAddress('192.0.2.18'), IPAddress('192.0.2.19')] (Extended slicing) . >>> list(ip[0::2]) [IPAddress('192.0.2.16'), IPAddress('192.0.2.18'), IPAddress('192.0.2.20'), IPAddress('192.0.2.22')] . >>> list(ip[-1::-1]) [IPAddress('192.0.2.23'), IPAddress('192.0.2.22'), ..., IPAddress('192.0.2.17'), IPAddress('192.0.2.16')] IP . >>> for ip in IPNetwork('192.0.2.0/23'): ... print('%s' % ip) ... 192.0.2.0 192.0.2.1 192.0.2.2 192.0.2.3 ... 192.0.3.252 192.0.3.253 192.0.3.254 192.0.3.255 IPv4 (broadcast) . (iterator) IP : >>> for ip in IPNetwork('192.0.2.0/23').iter_hosts(): ... print('%s' % ip) ... 192.0.2.1 192.0.2.2 192.0.2.3 192.0.2.4 ... 192.0.3.251 192.0.3.252 192.0.3.253 192.0.3.254 IP (Sorting IP addresses and networks) IP . : >>> import random >>> ip_list = list(IPNetwork('192.0.2.128/28')) >>> random.shuffle(ip_list) >>> sorted(ip_list) [IPAddress('192.0.2.128'), IPAddress('192.0.2.129'), ..., IPAddress('192.0.2.142'), IPAddress('192.0.2.143')] IP IPv4 IPv6 ( IPv4 IPv6 ). >>> ip_list = [ ... IPAddress('192.0.2.130'), ... IPAddress('10.0.0.1'), ... IPNetwork('192.0.2.128/28'), ... IPNetwork('192.0.3.0/24'), ... IPNetwork('192.0.2.0/24'), ... IPNetwork('fe80::/64'), ... IPAddress('::')] >>> random.shuffle(ip_list) >>> ip_list.sort() >>> pprint.pprint(ip_list) [IPAddress('10.0.0.1'), IPNetwork('192.0.2.0/24'), IPNetwork('192.0.2.128/28'), IPAddress('192.0.2.130'), IPNetwork('192.0.3.0/24'), IPAddress('::'), IPNetwork('fe80::/64')] ..SS " (Summarizing list of addresses and subnets)" IP CIDR . netaddr cidr_merge() . IP IP . IPv6 . >>> ip_list = [ip for ip in IPNetwork('fe80::/120')] >>> ip_list.append(IPNetwork('192.0.2.0/24')) >>> ip_list.extend([str(ip) for ip in IPNetwork('192.0.3.0/24')]) >>> ip_list.append(IPNetwork('192.0.4.0/25')) >>> ip_list.append(IPNetwork('192.0.4.128/25')) >>> len(ip_list) 515 >>> cidr_merge(ip_list) [IPNetwork('192.0.2.0/23'), IPNetwork('192.0.4.0/24'), IPNetwork('fe80::/120')] (Supernets and subnets) CIDR (firewall) netaddr . B /16 . >>> ip = IPNetwork('172.24.0.0/16') >>> ip.subnet(23) (iterator) . >>> subnets = list(ip.subnet(23)) >>> len(subnets) 128 >>> subnets [IPNetwork('172.24.0.0/23'), IPNetwork('172.24.2.0/23'), IPNetwork('172.24.4.0/23'), ..., IPNetwork('172.24.250.0/23'), IPNetwork('172.24.252.0/23'), IPNetwork('172.24.254.0/23')] (supernets) IP . . >>> ip = IPNetwork('192.0.2.114') >>> supernets = ip.supernet(22) >>> pprint.pprint(supernets) [IPNetwork('192.0.0.0/22'), IPNetwork('192.0.2.0/23'), IPNetwork('192.0.2.0/24'), IPNetwork('192.0.2.0/25'), IPNetwork('192.0.2.64/26'), IPNetwork('192.0.2.96/27'), IPNetwork('192.0.2.112/28'), IPNetwork('192.0.2.112/29'), IPNetwork('192.0.2.112/30'), IPNetwork('192.0.2.114/31')] (generator) ( IPv4 IPv6). (Support for non-standard address ranges) CIDR ( IPv4 CIDR ) IP . iter_iprange() . >>> ip_list = list(iter_iprange('192.0.2.1', '192.0.2.14')) >>> len(ip_list) 14 >>> ip_list [IPAddress('192.0.2.1'), IPAddress('192.0.2.2'), ..., IPAddress('192.0.2.13'), IPAddress('192.0.2.14')] CIDR . cidr_merge() . >>> cidr_merge(ip_list) [IPNetwork('192.0.2.1/32'), IPNetwork('192.0.2.2/31'), IPNetwork('192.0.2.4/30'), IPNetwork('192.0.2.8/30'), IPNetwork('192.0.2.12/31'), IPNetwork('192.0.2.14/32')] CIDR netmask IPv4 octet (classful RFC 791 ) . RFC . ( ) cidr_abbrev_to_verbose() . IPv4 . >>> cidrs = [cidr_abbrev_to_verbose(octet) for octet in range(0, 256)] >>> pprint.pprint(cidrs) ['0.0.0.0/8', ... '127.0.0.0/8', '128.0.0.0/16', ... '191.0.0.0/16', '192.0.0.0/24', ... '223.0.0.0/24', '224.0.0.0/4', ... '239.0.0.0/4', '240.0.0.0/32', ... '255.0.0.0/32'] >>> len(cidrs) 256 IP IP (host) . (Unicast) >>> IPAddress('192.0.2.1').is_unicast() True >>> IPAddress('fe80::1').is_unicast() True (Multicast) ( RFC 2365 3171 ). >>> IPAddress('239.192.0.1').is_multicast() True >>> IPAddress('ff00::1').is_multicast() True (Reserved) . >>> IPAddress('253.0.0.1').is_reserved() True (Netmasks) IP . >>> IPAddress('255.255.254.0').is_netmask() True (Hostmasks) netmask . >>> IPAddress('0.0.1.255').is_hostmask() True (Loopback) IP . >>> IPAddress('127.0.0.1').is_loopback() True >>> IPAddress('::1').is_loopback() True IPAddress . IPAddress IP . IP . >>> IPAddress('192.0.2.1') == IPAddress('192.0.2.1') True >>> IPAddress('192.0.2.1') < IPAddress('192.0.2.2') True >>> IPAddress('192.0.2.2') > IPAddress('192.0.2.1') True >>> IPAddress('192.0.2.1') != IPAddress('192.0.2.1') False >>> IPAddress('192.0.2.1') >= IPAddress('192.0.2.1') True >>> IPAddress('192.0.2.2') >= IPAddress('192.0.2.1') True >>> IPAddress('192.0.2.1') <= IPAddress('192.0.2.1') True >>> IPAddress('192.0.2.1') <= IPAddress('192.0.2.2') True . >>> IPNetwork('192.0.2.0/24') == IPNetwork('192.0.2.112/24') True ... IP ( ) IP . . IP . >>> IPNetwork('192.0.2.0/24').ip == IPNetwork('192.0.2.112/24').ip False >>> IPNetwork('192.0.2.0/24').ip < IPNetwork('192.0.2.112/24').ip True ! ( ). >>> IPNetwork('192.0.2.0/24').cidr == IPNetwork('192.0.2.112/24').cidr True . >>> IPNetwork('192.0.2.0/24') == IPNetwork('192.0.3.0/24') False >>> IPNetwork('192.0.2.0/24') < IPNetwork('192.0.3.0/24') True IPAddress () IPNetwork () ( ). netaddr . >>> IPAddress('192.0.2.0') == IPNetwork('192.0.2.0/32') False >>> IPAddress('192.0.2.0') != IPNetwork('192.0.2.0/32') True IP IP ( ) . IP IP . /32 : >>> IPAddress('192.0.2.0') == IPNetwork('192.0.2.0/32')[0] True >>> IPAddress('192.0.2.0') == IPNetwork('192.0.2.0/32')[-1] True >>> IPAddress('192.0.2.0') != IPNetwork('192.0.2.0/32')[0] False : >>> IPAddress('192.0.2.0') == IPNetwork('192.0.2.0/32').ip True >>> IPAddress('192.0.2.0') != IPNetwork('192.0.2.0/32').ip False netaddr IP ..SS DNS IP DNS . IPv6 . reverse_dns() IPAddress . >>> IPAddress('172.24.0.13').reverse_dns '13.0.24.172.in-addr.arpa.' >>> IPAddress('fe80::feeb:daed').reverse_dns 'd.e.a.d.b.e.e.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa.' ip6.int ( RFC 3152 ). IP CIDR IP CIDR . CIDR . netaddr . IP IP IPRange . >>> r1 = IPRange('192.0.2.1', '192.0.2.15') >>> r1 IPRange('192.0.2.1', '192.0.2.15') IPNetwork . CIDR . >>> r1.cidrs() [IPNetwork('192.0.2.1/32'), IPNetwork('192.0.2.2/31'), IPNetwork('192.0.2.4/30'), IPNetwork('192.0.2.8/29')] IPRange IPNetwork . >>> IPRange('192.0.2.0', '192.0.2.255') != IPNetwork('192.0.2.0/24') False >>> IPRange('192.0.2.0', '192.0.2.255') == IPNetwork('192.0.2.0/24') True IP IPAddress IPNetwork . >>> r1 = IPRange('192.0.2.1', '192.0.2.15') >>> addrs = list(r1) >>> addrs [IPAddress('192.0.2.1'), IPAddress('192.0.2.2'), IPAddress('192.0.2.3'), IPAddress('192.0.2.4'), IPAddress('192.0.2.5'), IPAddress('192.0.2.6'), IPAddress('192.0.2.7'), IPAddress('192.0.2.8'), IPAddress('192.0.2.9'), IPAddress('192.0.2.10'), IPAddress('192.0.2.11'), IPAddress('192.0.2.12'), IPAddress('192.0.2.13'), IPAddress('192.0.2.14'), IPAddress('192.0.2.15')] >>> r1 == addrs False ! . . >>> list(r1) == addrs True . IPNetwork . >>> subnets = r1.cidrs() >>> subnets [IPNetwork('192.0.2.1/32'), IPNetwork('192.0.2.2/31'), IPNetwork('192.0.2.4/30'), IPNetwork('192.0.2.8/29')] >>> r1 == subnets False >>> r1.cidrs() == subnets True IPAddress IPNetwork . IP : IPSet. >>> ips = [IPAddress('192.0.2.1'), '192.0.2.2/31', IPNetwork('192.0.2.4/31'), IPAddress('192.0.2.6'), IPAddress('192.0.2.7'), '192.0.2.8', '192.0.2.9', IPAddress('192.0.2.10'), IPAddress('192.0.2.11'), IPNetwork('192.0.2.12/30')] >>> s1 = IPSet(r1.cidrs()) >>> s2 = IPSet(ips) >>> s2 IPSet(['192.0.2.1/32', '192.0.2.2/31', '192.0.2.4/30', '192.0.2.8/29']) >>> s1 == s2 True IPSet . >>> s2.pop() IPNetwork('...') >>> s1 == s2 False . IPSet Tutorial 3: Working with IP sets <> ..SS IP (IP Glob ranges) netaddr IP <> . : glob IPv4 . >>> IPGlob('192.0.2.*') == IPNetwork('192.0.2.0/24') True >>> IPGlob('192.0.2.*') != IPNetwork('192.0.2.0/24') False IPGlob IPRange . : MAC (MAC addresses) MAC (namespace) . : . (name clashes) . >>> from netaddr import * netaddr . . (Basic operations) EUI MAC . >>> mac = EUI('00-1B-77-49-54-FD') repr() MAC . >>> mac EUI('00-1B-77-49-54-FD') EUI (). >>> str(mac) '00-1B-77-49-54-FD' >>> '%s' % mac '00-1B-77-49-54-FD' . >>> str(mac), str(mac.oui), mac.ei, mac.version ('00-1B-77-49-54-FD', '00-1B-77', '49-54-FD', 48) (Numerical representations) MAC . >>> int(mac) == 117965411581 True >>> hex(mac) '0x1b774954fd' >>> oct(mac) '0o1556722252375' >>> mac.bits() '00000000-00011011-01110111-01001001-01010100-11111101' >>> mac.bin '0b1101101110111010010010101010011111101' MAC IEEE EUI-48 . EUI . >>> EUI('00-1B-77-49-54-FD') EUI('00-1B-77-49-54-FD') IEEE EUI-48 >>> EUI('00-1b-77-49-54-fd') EUI('00-1B-77-49-54-FD') UNIX >>> EUI('0:1b:77:49:54:fd') EUI('00-1B-77-49-54-FD') (triple hextet) (Cisco) >>> EUI('001b:7749:54fd') EUI('00-1B-77-49-54-FD') >>> EUI('1b:7749:54fd') EUI('00-1B-77-49-54-FD') >>> EUI('1B:7749:54FD') EUI('00-1B-77-49-54-FD') MAC ( ) >>> EUI('001b774954fd') EUI('00-1B-77-49-54-FD') >>> EUI('01B774954FD') EUI('00-1B-77-49-54-FD') PostgreSQL ( ) >>> EUI('001B77:4954FD') EUI('00-1B-77-49-54-FD') MAC 'dialect' . dialect csv Python . >>> mac = EUI('00-1B-77-49-54-FD') >>> mac EUI('00-1B-77-49-54-FD') >>> mac.dialect = mac_unix >>> mac EUI('0:1b:77:49:54:fd') >>> mac.dialect = mac_unix_expanded >>> mac EUI('00:1b:77:49:54:fd') >>> mac.dialect = mac_cisco >>> mac EUI('001b.7749.54fd') >>> mac.dialect = mac_bare >>> mac EUI('001B774954FD') >>> mac.dialect = mac_pgsql >>> mac EUI('001b77:4954fd') dialect MAC . dialect UNIX MAC (octets) . >>> class mac_custom(mac_unix): pass >>> mac_custom.word_fmt = '%.2X' >>> mac = EUI('00-1B-77-49-54-FD', dialect=mac_custom) >>> mac EUI('00:1B:77:49:54:FD') EUI OUI ( Organisationally Unique Identifier) IAB ( Individual Address Block) IEEE . OUI EUI : >>> mac = EUI('00-1B-77-49-54-FD') >>> oui = mac.oui >>> oui OUI('00-1B-77') >>> oui.registration().address ['Lot 8, Jalan Hi-Tech 2/3', 'Kulim Kedah 09000', 'MY'] >>> oui.registration().org 'Intel Corporate' EUI OUI . OUI . IEEE. : >>> oui = OUI(524336) # OUI constructor accepts integer values, too. >>> oui OUI('08-00-30') >>> oui.registration(0).address ['2380 N. ROSE AVENUE', 'OXNARD CA 93010', 'US'] >>> oui.registration(0).org 'NETWORK RESEARCH CORPORATION' >>> oui.registration(0).oui '08-00-30' >>> oui.registration(1).address ['GPO BOX 2476V', 'MELBOURNE VIC 3001', 'AU'] >>> oui.registration(1).org 'ROYAL MELBOURNE INST OF TECH' >>> oui.registration(1).oui '08-00-30' >>> oui.registration(2).address ['CH-1211', 'GENEVE SUISSE/SWITZ 023', 'CH'] >>> oui.registration(2).org 'CERN' >>> oui.registration(2).oui '08-00-30' >>> for i in range(oui.reg_count): ... str(oui), oui.registration(i).org ... ('08-00-30', 'NETWORK RESEARCH CORPORATION') ('08-00-30', 'ROYAL MELBOURNE INST OF TECH') ('08-00-30', 'CERN') IAB EUI : >>> mac = EUI('00-50-C2-00-0F-01') >>> mac.is_iab() True >>> iab = mac.iab >>> iab IAB('00-50-C2-00-00-00') >>> iab.registration() {'address': ['1241 Superieor Ave E', 'Cleveland OH 44114', 'US'], 'iab': '00-50-C2-00-00-00', 'idx': 84680704, ... 'org': 'T.L.S. Corp.', 'size': 537} : IP netaddr (namespace) . : . . >>> from netaddr import * IP . . >>> IPSet() IPSet([]) >>> IPSet([]) IPSet([]) >>> len(IPSet([])) 0 IP . IPAddress IPNetwork IPRange IPSet . >>> IPSet(['192.0.2.0']) IPSet(['192.0.2.0/32']) >>> IPSet([IPAddress('192.0.2.0')]) IPSet(['192.0.2.0/32']) >>> IPSet([IPNetwork('192.0.2.0')]) IPSet(['192.0.2.0/32']) >>> IPSet(IPNetwork('1234::/32')) IPSet(['1234::/32']) >>> IPSet([IPNetwork('192.0.2.0/24')]) IPSet(['192.0.2.0/24']) >>> IPSet(IPSet(['192.0.2.0/32'])) IPSet(['192.0.2.0/32']) >>> IPSet(IPRange("10.0.0.0", "10.0.1.31")) IPSet(['10.0.0.0/24', '10.0.1.0/27']) >>> IPSet(IPRange('0.0.0.0', '255.255.255.255')) IPSet(['0.0.0.0/0']) IP IP . >>> for ip in IPSet(['192.0.2.0/28', '::ffff:192.0.2.0/124']): ... print(ip) 192.0.2.0 192.0.2.1 192.0.2.2 192.0.2.3 192.0.2.4 192.0.2.5 192.0.2.6 192.0.2.7 192.0.2.8 192.0.2.9 192.0.2.10 192.0.2.11 192.0.2.12 192.0.2.13 192.0.2.14 192.0.2.15 ::ffff:192.0.2.0 ::ffff:192.0.2.1 ::ffff:192.0.2.2 ::ffff:192.0.2.3 ::ffff:192.0.2.4 ::ffff:192.0.2.5 ::ffff:192.0.2.6 ::ffff:192.0.2.7 ::ffff:192.0.2.8 ::ffff:192.0.2.9 ::ffff:192.0.2.10 ::ffff:192.0.2.11 ::ffff:192.0.2.12 ::ffff:192.0.2.13 ::ffff:192.0.2.14 ::ffff:192.0.2.15 >>> s1 = IPSet() >>> s1.add('192.0.2.0') >>> s1 IPSet(['192.0.2.0/32']) >>> s1.remove('192.0.2.0') >>> s1 IPSet([]) >>> s1.add(IPRange("10.0.0.0", "10.0.0.255")) >>> s1 IPSet(['10.0.0.0/24']) >>> s1.remove(IPRange("10.0.0.128", "10.10.10.10")) >>> s1 IPSet(['10.0.0.0/25']) IP . >>> iprange = IPRange('192.0.1.255', '192.0.2.16') CIDR . >>> iprange.cidrs() [IPNetwork('192.0.1.255/32'), IPNetwork('192.0.2.0/28'), IPNetwork('192.0.2.16/32')] IP . >>> ipset = IPSet(['192.0.2.0/28']) IP IP . >>> for ip in iprange: ... print(ip, ip in ipset) 192.0.1.255 False 192.0.2.0 True 192.0.2.1 True 192.0.2.2 True 192.0.2.3 True 192.0.2.4 True 192.0.2.5 True 192.0.2.6 True 192.0.2.7 True 192.0.2.8 True 192.0.2.9 True 192.0.2.10 True 192.0.2.11 True 192.0.2.12 True 192.0.2.13 True 192.0.2.14 True 192.0.2.15 True 192.0.2.16 False IPSet >>> bigone = IPSet(['0.0.0.0/0']) >>> IPAddress("10.0.0.1") in bigone True >>> IPAddress("0.0.0.0") in bigone True >>> IPAddress("255.255.255.0") in bigone True >>> IPNetwork("10.0.0.0/24") in bigone True >>> IPAddress("::1") in bigone False >>> smallone = IPSet(["10.0.0.42/32"]) >>> IPAddress("10.0.0.42") in smallone True >>> IPAddress("10.0.0.41") in smallone False >>> IPAddress("10.0.0.43") in smallone False >>> IPNetwork("10.0.0.42/32") in smallone True >>> IPNetwork("10.0.0.42/31") in smallone False (Unions, intersections and differences) IPSet . >>> IPSet(['192.0.2.0']) IPSet(['192.0.2.0/32']) >>> IPSet(['192.0.2.0']) | IPSet(['192.0.2.1']) IPSet(['192.0.2.0/31']) >>> IPSet(['192.0.2.0']) | IPSet(['192.0.2.1']) | IPSet(['192.0.2.3']) IPSet(['192.0.2.0/31', '192.0.2.3/32']) >>> IPSet(['192.0.2.0']) | IPSet(['192.0.2.1']) | IPSet(['192.0.2.3/30']) IPSet(['192.0.2.0/30']) >>> IPSet(['192.0.2.0']) | IPSet(['192.0.2.1']) | IPSet(['192.0.2.3/31']) IPSet(['192.0.2.0/30']) >>> IPSet(['192.0.2.0/24']) | IPSet(['192.0.3.0/24']) | IPSet(['192.0.4.0/24']) IPSet(['192.0.2.0/23', '192.0.4.0/24']) . >>> adj_cidrs = list(IPNetwork('192.0.2.0/24').subnet(28)) >>> even_cidrs = adj_cidrs[::2] >>> evens = IPSet(even_cidrs) >>> evens IPSet(['192.0.2.0/28', '192.0.2.32/28', '192.0.2.64/28', '192.0.2.96/28', '192.0.2.128/28', '192.0.2.160/28', '192.0.2.192/28', '192.0.2.224/28']) >>> IPSet(['192.0.2.0/24']) & evens IPSet(['192.0.2.0/28', '192.0.2.32/28', '192.0.2.64/28', '192.0.2.96/28', '192.0.2.128/28', '192.0.2.160/28', '192.0.2.192/28', '192.0.2.224/28']) >>> odds = IPSet(['192.0.2.0/24']) ^ evens >>> odds IPSet(['192.0.2.16/28', '192.0.2.48/28', '192.0.2.80/28', '192.0.2.112/28', '192.0.2.144/28', '192.0.2.176/28', '192.0.2.208/28', '192.0.2.240/28']) >>> evens | odds IPSet(['192.0.2.0/24']) >>> evens & odds IPSet([]) >>> evens ^ odds IPSet(['192.0.2.0/24']) IP . >>> s1 = IPSet(['192.0.2.0/24', '192.0.4.0/24']) >>> s2 = IPSet(['192.0.2.0', '192.0.4.0']) >>> s1 IPSet(['192.0.2.0/24', '192.0.4.0/24']) >>> s2 IPSet(['192.0.2.0/32', '192.0.4.0/32']) >>> s1.issuperset(s2) True >>> s2.issubset(s1) True >>> s2.issuperset(s1) False >>> s1.issubset(s2) False IPv4 . >>> ipv4_addr_space = IPSet(['0.0.0.0/0']) >>> private = IPSet(['10.0.0.0/8', '172.16.0.0/12', '192.0.2.0/24', '192.168.0.0/16', '239.192.0.0/14']) >>> reserved = IPSet(['225.0.0.0/8', '226.0.0.0/7', '228.0.0.0/6', '234.0.0.0/7', '236.0.0.0/7', '238.0.0.0/8', '240.0.0.0/4']) >>> unavailable = reserved | private >>> available = ipv4_addr_space ^ unavailable : >>> for cidr in available.iter_cidrs(): ... print(cidr, cidr[0], cidr[-1]) 0.0.0.0/5 0.0.0.0 7.255.255.255 8.0.0.0/7 8.0.0.0 9.255.255.255 11.0.0.0/8 11.0.0.0 11.255.255.255 12.0.0.0/6 12.0.0.0 15.255.255.255 16.0.0.0/4 16.0.0.0 31.255.255.255 32.0.0.0/3 32.0.0.0 63.255.255.255 64.0.0.0/2 64.0.0.0 127.255.255.255 128.0.0.0/3 128.0.0.0 159.255.255.255 160.0.0.0/5 160.0.0.0 167.255.255.255 168.0.0.0/6 168.0.0.0 171.255.255.255 172.0.0.0/12 172.0.0.0 172.15.255.255 172.32.0.0/11 172.32.0.0 172.63.255.255 172.64.0.0/10 172.64.0.0 172.127.255.255 172.128.0.0/9 172.128.0.0 172.255.255.255 173.0.0.0/8 173.0.0.0 173.255.255.255 174.0.0.0/7 174.0.0.0 175.255.255.255 176.0.0.0/4 176.0.0.0 191.255.255.255 192.0.0.0/23 192.0.0.0 192.0.1.255 192.0.3.0/24 192.0.3.0 192.0.3.255 192.0.4.0/22 192.0.4.0 192.0.7.255 192.0.8.0/21 192.0.8.0 192.0.15.255 192.0.16.0/20 192.0.16.0 192.0.31.255 192.0.32.0/19 192.0.32.0 192.0.63.255 192.0.64.0/18 192.0.64.0 192.0.127.255 192.0.128.0/17 192.0.128.0 192.0.255.255 192.1.0.0/16 192.1.0.0 192.1.255.255 192.2.0.0/15 192.2.0.0 192.3.255.255 192.4.0.0/14 192.4.0.0 192.7.255.255 192.8.0.0/13 192.8.0.0 192.15.255.255 192.16.0.0/12 192.16.0.0 192.31.255.255 192.32.0.0/11 192.32.0.0 192.63.255.255 192.64.0.0/10 192.64.0.0 192.127.255.255 192.128.0.0/11 192.128.0.0 192.159.255.255 192.160.0.0/13 192.160.0.0 192.167.255.255 192.169.0.0/16 192.169.0.0 192.169.255.255 192.170.0.0/15 192.170.0.0 192.171.255.255 192.172.0.0/14 192.172.0.0 192.175.255.255 192.176.0.0/12 192.176.0.0 192.191.255.255 192.192.0.0/10 192.192.0.0 192.255.255.255 193.0.0.0/8 193.0.0.0 193.255.255.255 194.0.0.0/7 194.0.0.0 195.255.255.255 196.0.0.0/6 196.0.0.0 199.255.255.255 200.0.0.0/5 200.0.0.0 207.255.255.255 208.0.0.0/4 208.0.0.0 223.255.255.255 224.0.0.0/8 224.0.0.0 224.255.255.255 232.0.0.0/7 232.0.0.0 233.255.255.255 239.0.0.0/9 239.0.0.0 239.127.255.255 239.128.0.0/10 239.128.0.0 239.191.255.255 239.196.0.0/14 239.196.0.0 239.199.255.255 239.200.0.0/13 239.200.0.0 239.207.255.255 239.208.0.0/12 239.208.0.0 239.223.255.255 239.224.0.0/11 239.224.0.0 239.255.255.255 >>> ipv4_addr_space ^ available IPSet(['10.0.0.0/8', '172.16.0.0/12', '192.0.2.0/24', '192.168.0.0/16', '225.0.0.0/8', '226.0.0.0/7', '228.0.0.0/6', '234.0.0.0/7', '236.0.0.0/7', '238.0.0.0/8', '239.192.0.0/14', '240.0.0.0/4']) netaddr IPv4 IPv6 . >>> s1 = IPSet(['192.0.2.0', '::ffff:192.0.2.0', '192.0.2.2', '::ffff:192.0.2.2']) >>> s2 = IPSet(['192.0.2.2', '::ffff:192.0.2.2', '192.0.2.4', '::ffff:192.0.2.4']) >>> s1 IPSet(['192.0.2.0/32', '192.0.2.2/32', '::ffff:192.0.2.0/128', '::ffff:192.0.2.2/128']) >>> s2 IPSet(['192.0.2.2/32', '192.0.2.4/32', '::ffff:192.0.2.2/128', '::ffff:192.0.2.4/128']) IPv4 IPv6 >>> s1 | s2 IPSet(['192.0.2.0/32', '192.0.2.2/32', '192.0.2.4/32', '::ffff:192.0.2.0/128', '::ffff:192.0.2.2/128', '::ffff:192.0.2.4/128']) >>> s2 | s1 IPSet(['192.0.2.0/32', '192.0.2.2/32', '192.0.2.4/32', '::ffff:192.0.2.0/128', '::ffff:192.0.2.2/128', '::ffff:192.0.2.4/128']) >>> s1 & s2 IPSet(['192.0.2.2/32', '::ffff:192.0.2.2/128']) >>> s1 - s2 IPSet(['192.0.2.0/32', '::ffff:192.0.2.0/128']) >>> s2 - s1 IPSet(['192.0.2.4/32', '::ffff:192.0.2.4/128']) >>> s1 ^ s2 IPSet(['192.0.2.0/32', '192.0.2.4/32', '::ffff:192.0.2.0/128', '::ffff:192.0.2.4/128']) IP >>> s1 = IPSet(['192.0.2.0', '192.0.2.1', '192.0.2.2']) >>> s2 = IPSet(['192.0.2.2', '192.0.2.3', '192.0.2.4']) >>> s1 & s2 IPSet(['192.0.2.2/32']) >>> s1.isdisjoint(s2) False >>> s1 = IPSet(['192.0.2.0', '192.0.2.1']) >>> s2 = IPSet(['192.0.2.3', '192.0.2.4']) >>> s1 & s2 IPSet([]) >>> s1.isdisjoint(s2) True IP Python IP . >>> s1 = IPSet(['192.0.2.0/25']) >>> s1 IPSet(['192.0.2.0/25']) >>> s2 = IPSet(['192.0.2.128/25']) >>> s2 IPSet(['192.0.2.128/25']) >>> s1.update(s2) >>> s1 IPSet(['192.0.2.0/24']) >>> s1.update(['192.0.0.0/24', '192.0.1.0/24', '192.0.3.0/24']) >>> s1 IPSet(['192.0.0.0/22']) >>> s2 = IPSet(['10.0.0.0/16']) >>> s2.update(IPRange('10.1.0.0', '10.1.255.255')) >>> s2 IPSet(['10.0.0.0/15']) >>> s2.clear() >>> s2 IPSet([]) IP IPSet CIDR . IPv4 . >>> s1 = IPSet(['0.0.0.0/0']) >>> s1 IPSet(['0.0.0.0/0']) . >>> s1.remove('255.255.255.255') : >>> s1 IPSet(['0.0.0.0/1', '128.0.0.0/2', ..., '255.255.255.252/31', '255.255.255.254/32']) >>> list(s1.iter_cidrs()) [IPNetwork('0.0.0.0/1'), IPNetwork('128.0.0.0/2'), ..., IPNetwork('255.255.255.252/31'), IPNetwork('255.255.255.254/32')] >>> len(list(s1.iter_cidrs())) 32 cidr_exclude . >>> list(s1.iter_cidrs()) == cidr_exclude('0.0.0.0/0', '255.255.255.255') True . >>> s1.remove('0.0.0.0') CIDR . >>> s1 IPSet(['0.0.0.1/32', '0.0.0.2/31', ..., '255.255.255.252/31', '255.255.255.254/32']) >>> len(list(s1.iter_cidrs())) 62 IP . IP set IP IP . >>> s1.add('255.255.255.255') >>> s1 IPSet(['0.0.0.1/32', '0.0.0.2/31', ..., '64.0.0.0/2', '128.0.0.0/1']) . >>> list(s1.iter_cidrs()) [IPNetwork('0.0.0.1/32'), IPNetwork('0.0.0.2/31'), ..., IPNetwork('64.0.0.0/2'), IPNetwork('128.0.0.0/1')] >>> len(list(s1.iter_cidrs())) 32 IP . >>> s1.add('0.0.0.0') . >>> s1 IPSet(['0.0.0.0/0']) IPSet IPRange . >>> s1 = IPSet(['10.0.0.0/25', '10.0.0.128/25']) >>> s1.iprange() IPRange('10.0.0.0', '10.0.0.255') IPSet >>> s1.iscontiguous() True >>> s1.remove('10.0.0.16') >>> s1 IPSet(['10.0.0.0/28', '10.0.0.17/32', '10.0.0.18/31', '10.0.0.20/30', '10.0.0.24/29', '10.0.0.32/27', '10.0.0.64/26', '10.0.0.128/25']) >>> s1.iscontiguous() False >>> s1.iprange() Traceback (most recent call last): File "", line 1, in ValueError: IPSet is not contiguous IPSet IPRange . >>> list(s1.iter_ipranges()) [IPRange('10.0.0.0', '10.0.0.15'), IPRange('10.0.0.17', '10.0.0.255')] >>> s2 = IPSet(['0.0.0.0/0']) >>> s2.iscontiguous() True >>> s2.iprange() IPRange('0.0.0.0', '255.255.255.255') >>> s3 = IPSet() >>> s3.iscontiguous() True >>> s3.iprange() >>> s4 = IPSet(IPRange('10.0.0.0', '10.0.0.8')) >>> s4.iscontiguous() True (Pickling) IPSet netaddr pickle IP set . >>> import pickle >>> ip_data = IPSet(['10.0.0.0/16', 'fe80::/64']) >>> buf = pickle.dumps(ip_data) >>> ip_data_unpickled = pickle.loads(buf) >>> ip_data == ip_data_unpickled True IPSet >>> x = IPSet(['fc00::/2']) >>> y = IPSet(['fc00::/3']) >>> x > y True >>> x < y False >>> x != y True . netaddr . (PyPI) netaddr pip . PyPI - : pip install netaddr <#interactive-shell> IPython : pip install 'netaddr[nicer-shell]' IPython : pip install ipython netaddr . : netaddr . . : # Debian, Ubuntu sudo apt install python3-netaddr # Fedora # Base installation sudo dnf install python3-netaddr # The CLI tool sudo dnf install python3-netaddr-shell tarball/zip . : pip install . lib/site-packages virtualenv ..SH " (REFERENCE)" netaddr . Python netaddr (CPython PyPy) : o 3.7 o 3.8 o 3.9 o 3.10 o 3.11 o 3.12 1.0.0 : o 2.7 o 3.5 o 3.6 netaddr 2: o 3.7 . . API API netaddr . API . : o netaddr (from netaddr.X import Y) o (_X) o API IP IP : +---------+ +---------+ | ipv4(M) | | ipv6(M) | +---------+ +---------+ | | (HAS A) (HAS A) | | +-----+----------------+-----------------+ | | +--------|-------+---------|--------+--------+ | | | | | | | | | | | | v v v v | | +-----------+ +-----------+ | | | IPAddress | | IPNetwork | | | +-----------+ +-----------+ | | | | | | (HAS A) (HAS A) | | | | v v +-------+--------+ +------------+ | | IPRange | | +-----------+ v | +-------+ | | IPSet | v +-------+ +--------+ | IPGlob | +--------+ flags netaddr . netaddr.INET_PTON inet_pton() inet_aton() IPv4. IPAddress.__init__() . 1.0.0 : ( ). netaddr.INET_ATON inet_aton() IPv4. IPAddress.__init__() . 0.10.0 . netaddr.ZEROFILL IPv4 . IPAddress.__init__() . netaddr.NOHOST CIDR. IPNetwork.__init__() . IP IP ( ) . IPv4 IPv6 . IPAddress IP . IPv6 IPAddress.format . IP IPNetwork IP //VLAN . IP CIDR netmask . "" IPNetwork . IP netaddr IP IP . . IP . . IP glob IP CIDR . IPGlob glob . globbing glob CIDR IP . . nmap nmap . IP . IP . IP IP . IPSet . IP ..SS MAC IEEE EUI MAC 48- . ( ) . EUI MAC ( 64- ) . MAC MAC . . RFC 1924 - :-) (CLI) netaddr netaddr . : . . (: ) . API <> . : % netaddr --help __ __ __ ____ ___ / /_____ _____/ /___/ /____ / __ \/ _ \/ __/ __ `/ __ / __ / ___/ / / / / __/ /_/ /_/ / /_/ / /_/ / / /_/ /_/\___/\__/\__,_/\__,_/\__,_/_/ usage: netaddr [-h] The netaddr CLI tool options: -h, --help show this help message and exit Share and enjoy! netaddr . IPython REPL Python . REPL IPython . API netaddr <> (pre-imported) : % netaddr __ __ __ ____ ___ / /_____ _____/ /___/ /____ / __ \/ _ \/ __/ __ `/ __ / __ / ___/ / / / / __/ /_/ /_/ / /_/ / /_/ / / /_/ /_/\___/\__/\__,_/\__,_/\__,_/_/ netaddr shell 1.0.0 - an interactive shell for the netaddr library In [1]: '10.0.0.2' in IPNetwork('10.0.0.0/24') Out[1]: True In [2]: 1.2.0: IPython ..SS IP netaddr info : % netaddr info 192.2.2.27/24 __ __ __ ____ ___ / /_____ _____/ /___/ /____ / __ \/ _ \/ __/ __ `/ __ / __ / ___/ / / / / __/ /_/ /_/ / /_/ / /_/ / / /_/ /_/\___/\__/\__,_/\__,_/\__,_/_/ IP network information CIDR 192.2.2.0/24 Network IP 192.2.2.0 Network IP (binary) 11000000.00000010.00000010.00000000 Network IP (decimal) 3221357056 Network IP (hex) 0xc0020200 Subnet mask 255.255.255.0 Subnet mask (binary) 11111111.11111111.11111111.00000000 Broadcast IP 192.2.2.255 Range 192.2.2.0-192.2.2.255 Total addresses 256 Usable range 192.2.2.1-192.2.2.254 Usable addresses 254 netaddr . RFC RFC netaddr . IPv4 RFC 791 - Internet Protocol o RFC 1918 - Address Allocation for Private Internets o RFC 3330 - Special-Use IPv4 Addresses o RFC 3927 - Dynamic Configuration of IPv4 Link-Local Addresses o (IPv4) RFC 2365 - Administratively Scoped IP Multicast o RFC 3171 - IANA IPv4 Multicast Guidelines o RFC 3927 - Dynamic Configuration of IPv4 Link-Local Addresses o RFC 3330 - IPv4 o RFC 4291 - IPv6 o RFC 3306 - IPv6 Unicast o RFC 3956 - RP IPv6 o RFC 3879 - (Site Local) o RFC 4193 - Unicast IPv6 o RFC 4941 - o RFC 1924 - IPv6 o (CIDR) RFC 1338 - (Supernetting): o RFC 4632 - (CIDR): o API netaddr . (IANA) IANA o IPv4 o IPv6 o (Multicast) o IEEE (IEEE Organisation Registry) o OUI ( ) o IAB ( ) o (HOW-TO GUIDES) netaddr netaddr . o : pip install --upgrade wheel twine o master (pull). master () ( CI ). o CHANGELOG.rst . . o ( ): o - (patch version bump) o - (minor version bump) o - (major version bump) o . : o netaddr/__init__.py o docs/source/conf.py NEXT_NETADDR_VERSION ( ). o (commit) . o : make build-and-publish o (tag) : git tag -a x.y.z -m 'Release version x.y.z' make push_tags o GitHub Release push . CHANGELOG.rst "Full changelog" ( ). NEXT_NETADDR_VERSION : : 1.3.0 : 2024-05-28 : o IPNetwork expand_partial 1.1.0 : o musl o IPv6 IPAddress ZEROFILL <#netaddr .ZEROFILL> o NOHOST <#netaddr .NOHOST> IPNetwork : 1.2.1 : 2024-02-17 : o 1.2.0 PyPI - (yanked) . . : 1.2.0 : 2024-02-17 : o CLI <# cli-network-info>. : o <#interactive-shell> IPython. : o TypeError valid_ipv4() valid_ipv6(). : 1.1.0 : 2024-02-15 : o Python (GH #365 ). o expand_partial_ipv4_address() API . : o IPNetwork(...) in IPRange(...) (GH #157 ). o IPNetwork (GH #214 ). o IP 1.0.0 IPNetwork . implicit_prefix IPv4 . expand_partial_ipv4_address() . GH: #110 . o . : 2024-02-10 : o Python 3.7. o : N P Z. NOHOST <#netaddr.NOHOST> INET_PTON <# netaddr.INET_PTON> ZEROFILL <#netaddr.ZEROFILL> . o CIDR IPNetwork (implicit_prefix=True) cidr_abbrev_to_verbose() . o IPAddress.is_private. is_private : o IPAddress.is_link_local() o IPAddress.is_ipv4_private_use() o IPAddress.is_ipv6_unique_local() o IPAddress.is_global() is_private : o 100.64.0.0/10 - (Shared Address Space) o 192.0.0.0/24 - IETF ( - ) o 198.18.0.0/15 - (Benchmarking) o 239.0.0.0-239.255.255.255 - 240.0.0.0/4 239.0.0.0/8 - : o IPv4 INET_PTON <#netaddr.INET_PTON> ( ). ZEROFILL <# netaddr.ZEROFILL> . str . IPv4 IPAddress . o ( inet_aton()) IPv4 . INET_PTON <#netaddr.INET_PTON> . inet_aton() INET_ATON <#netaddr.INET_ATON> . str . IPv4 IPAddress . o valid_ipv4() . o 2024-02-10. : o False AddrFormatError valid_ipv4() valid_ipv6(). o dialect EUI (copy-construction). : 0.10.1 : 2024-01-02 : o : o : N P Z. NOHOST <#netaddr.NOHOST> INET_PTON <# netaddr.INET_PTON> ZEROFILL <#netaddr.ZEROFILL> . o netaddr. netaddr . . o IPv4 valid_ipv4(). inet_pton() ( ) . INET_ATON <#netaddr.INET_ATON> / ZEROFILL <#netaddr .ZEROFILL> . : 2023-12-31 : o INET_ATON <#netaddr.INET_ATON> IPv4 inet_aton() IPAddress. o IPAddress.is_ipv4_private_use(). o IPAddress.is_global() . o IPAddress.is_ipv6_unique_local(). : o Python 3.13 John Eckersberg. : o Python 3.7. o CIDR IPNetwork (implicit_prefix=True). o IPv4 INET_PTON <# netaddr.INET_PTON> ( ). ZEROFILL <# netaddr.ZEROFILL> . str . IPv4 IPAddress . o IPv4 ( inet_aton()). INET_PTON <#netaddr.INET_PTON> . inet_aton() INET_ATON <#netaddr.INET_ATON> . str . IPv4 IPAddress . o IPAddress.is_private. . : o IPAddress IPNetwork IPRange. o . o DB (2023-12-23). : 0.9.0 (Release: 0.9.0) : 2023-09-18 : o (hash) OUI (#225, amitmi704) : o : IPv6 RFC 6164 ( IP --) ($267, Damien Claisse) o : is_loopback - IPNetwork('::1/128') (#222, #223, niels) o (#215, Louis Sautier) o (#242, Wouter) o print Python 3 (#221, Francois Magimel) o Sphinx (#220, Francois Magimel) : o (#266, Jakub Stasiak) o Python 3.6 (#263, Jakub Stasiak) o eval (#228, KOLANICH) : 3 2020 0.7.20 o (weak reference) __slots__ o __bytes__ IPAddress Michael Belousov. o format() EUI Omer Anson. o (property setter) IPNetwork.netmask Naveen Nathan. o IAB OUI 40:D8:55 Brian Maissy. o spanning_cidr() Brian Maissy. o "x.x.x.x/x" in IPNetwork xpac1985. o IPRange IPSet cidr_merge() Henry Stern. FIXED Issue 205: o N log N FIXED Issue 171: o IPSet IPRange FIXED Issue 161: o (Miscellanea) o (0.9.0) IPNetwork . IPv6 RFC 6164 ( /127 /128) : IPNetwork.broadcast None IPNetwork IPNetwork.iter_hosts() . ( 2984c0a40a70 ) . : 0.7.20 : 19 2020 0.7.19 o Python 3.7+ Sergey Kozlov. o (SyntaxWarning) Python 3.8 is not Stefan Nordhausen. o DeprecationWarnings (raw strings) (regex) Sean McGinnis. o IPGlob obkmeta. o (tuple) Matthias Urlichs. o shebang . o __file__ ( PyOxidizer). o . FIXED Issue 182: o test_ip_splitter_remove_prefix_larger_than_input_range python 3.7 FIXED Issue 206: o ""is not" with a literal." SyntaxWarning FIXED Issue 198: o oui FIXED Issue 188: o __file__ o Python 2 2.7 Python 3 3.5 . CI . o Python 2.7 3.5 (end-of-life) 2.7 3.5 . o CI Python Mac Linux Windows . : 0.7.19 (Release: 0.7.19) : (11 Jan 2017) 0.7.18 (Changes since 0.7.18) o SubnetSplitter . alanwill RyPeck (Stack Overflow discussion). o pytest "python setup.py test". o setup.py setuptools ( distutils) setup_egg.py . o INSTALL Python . o IEEE Python 2.x 3.x. (Specific bug fixes addressed in this release) FIXED Issue 133: o (prefix) FIXED Issue 129: o IPAddress().netmask_bits 0 0.0.0.0 [::] FIXED Issue 117: o (python setup.py test) python3 >= 3.5 FIXED Issue 137: o API ReadTheDocs FIXED Issue 143: o IANA IEEE (Miscellanea) o NYSE Euronext ( ) Intercontinental Exchange ... : 0.7.18 (Release: 0.7.18) : (4 Sep 2015) 0.7.17 (Changes since 0.7.17) o cidr_merge() O(n) . Anand Buddhdev (aabdnn) Stefan Nordhausen (snordhausen). o nmap CIDR IPv4 IPv6. FIXED Issue 100: o nmap.py - CIDR FIXED Issue 112: o : netaddr pypy : 0.7.17 : 0.7.16 o valid_mac shadow import netaddr. FIXED Issue 114: o netaddr.valid_mac('00-B0-D0-86-BB-F7')==False 0.7.16 True 0.7.15 : 0.7.16 : 0.7.15 o IPv4 netmask /31 /32 RFC 3021 . kalombos braaen. FIXED Issue 109: o unicast IPv6 FIXED Issue 108: o FIXED Issue 106: o Eui64 ( Issue 105) FIXED Issue 105: o dialect EUI-64 FIXED Issue 102: o tarball 0.7.15 . FIXED Issue 96: o /31 /32. : 0.7.14 o IPSet.__contains__. novas0x2a . o IPNetwork IPSet o py.test : o py.test : o IPSet.__contains__ IPRange : o IPSet : 0.7.14 : 0.7.13 o 0.7.13 ( Python OUI ). o EUI OUI IAB . : my_mac = EUI("11:22:33:44:55:66") my_mac == "11:22:33:44:55:66" Python "==" True . o "!=" OUI IAB Python2. Python3 . o EUI "-" . ":" EUI . : o L2 : o OUI 0.7.13 : o python netaddr-0.7.13-py2.py3-none-any.whl : o eui64 (:) . : 31 2014 0.7.12 o IPAddress Issue 73: o IP Issue 74: o IPv6 MAC Issue 75: o (classifiers) python 3.3 3.4 : 0.7.12 : 6 2014 0.7.11 o IPSet.iter_ipranges() . o bool(IPSet()) IPSet IPSet(['2405:8100::/32']). o IPNetwork.iter_hosts anycast subnet-router IPv6 . o fbsocket.inet_aton Issue 69: o __nonzero__ IPSet Pull Request 68: o ::0 iter_hosts v6 Issue 67: o fbsocket.inet_aton Pull Request 66: o IPRange IPSet : 0.7.11 : 19 2014 0.7.10 o IPSet Stefan Nordhausen Martijn van Oosterhout. IPSet(IPNetwork("10.0.0.0/8")) . o . o netaddr PyPI pip . o "10.0.0.42" in IPNetwork("10.0.0.0/24") . o IPSet : iscontiguous() iprange() Louis des Landes. o IPAddress.netmask_bits() . o 128.0.0.0/16 191.255.0.0/16 223.255.255.0/24 IPv4 . marnickv . o Wilfred Hughes 2*yo Adam Goodman. 58: o foo.bar AddrFormatError 57: o netaddr PyPI 56: o IPSet() 55: o smallest_matching_cidr all_matching_cidrs 53: o 128.0.0.0/16 51: o netaddr/eui/oui.txt 46: o len(IPSet()) python3 43: o IPSet 38: o netmask_bits IPAddress 37: o Python 3.3 : 0.7.9 o Python 3.x. Arfrever. o nmap . Issue 36 - o ResourceWarnings Python >=3.2 Issue 35 - o netaddr-0.7.9: Python 3 Issue 34 - o netaddr.ip.iana.SaxRecordParser.endElement() Python 3.1 Issue 33 - o netaddr Python 3 Issue 23 - o valid_nmap_range() nmap . Issue 22 - o all_matching_cidrs: : 0.7.9 : 0.7.8 o Sphinx. : 0.7.8 : 0.7.7 o SAX IANA ( Andrew Stromnov) o pickling EUI OUI IAB. Issue 31 - o '39.0.0.0/8' . Andrew Stromnov Issue 28 - o ipv6_link_local rfc4291. Philipp Wollermann Issue 25 - o install_requires Adam Lindsay . Issue 21 - o deepcopy EUI. Ryan Nowakowski. : 0.7.6 o ! Sphinx ! o o IEEE OUI IAB 24 - o TypeError BaseIP BaseIP. pvaret 17 - o .subnet() ipv6 . daveyss 20 - o Python 3. Arfrever : 0.7.6 : 0.7.5 o o (3rd party) o Python 3.2.x PyPy 1.6.x o Mac OSX 15 - o glob * 13 - o API IPython 0.11. juliantaylor 11 - o valid_glob cidr ValueError . radicand 7 - o Unpickling IPSet. LuizOz labeneator 2 - o UnboundLocalError IPNetwork. keesbos o NIC : 0.7.5 (Release: 0.7.5) : 0.7.4 (Changes since 0.7.4) o Python 3.x . ( ) ! - o github . svn2git . - () o netaddr __slots__ . Stefan Nordhausen ! o . o IPNetwork ( inet_aton ). o .value IPAddress IPNetwork IP . . . (Specific bug fixes addressed in this release) - o IP IP - o CIDR - o ipv6 cidr ipv4 [sic] - o - o IP - o Python 3.x - o IPAddress IPNetwork - o netaddr pickle - o IPSet IPAddress - o netaddr (coprocess) PowerDNS o standards.ieee.org ! o Sun Microsystems Merrill Lynch Oracle Bank of America ... : 0.7.4 : 0.7.3 o S. Nordhausen o EUI IPAddress. EUI.packed EUI.bin ( ) words(). : 0.7.3 : 0.7.2 o __add__ __radd__ __sub__ __rsub__ IPAddress. o IPv4 nmap ( Issue 46). o fallback socket. Issue 44 - o int/long Issue 46 - o IPv4 Issue 47 - o IPNetwork (boolean) : 0.7.2 : 0.7.1 iter_iprange() . o cidr_merge() pre-compiled . o README John Eckersberg. : Issue 43 - o IPNetwork('0.0.0.0/0') for : 0.7.1 : 0.7 o netaddr 'nash' 'netaddr' . . John Eckersberg ! o IANA IEEE . : Issue 42 - o cidr_merge() CIDR 0.0.0.0/0 / ::/0 : 0.7 : 0.6.x - netaddr . . API . :- o . . netaddr . o <<>> AT_* ST_*. o Addr . EUI IP . o . o netaddr.strategy . IP EUI . o . API . o IP CIDR IPAddress IPNetwork . IP netaddr . IP IP . IPAddress . netmask CIDR IPNetwork . o IP . o IP ( Wildcards ) . o IPSet . 0.5.x 0.6.x IPRangeSet CIDRGroup . . o 'fmt' . . IPAddress . o docstring . . coverage 3.x . o nash - netaddr ( IPython). o RFC 1924 ;-) 13 - o CIDR 26 - o isinstance() 28 - o 34 - o : 0.6.4 : 11 2009 40 - o RPM "python setup.py bdist_rpm" : 0.6.3 : 23 2009 0.6.2 o (line endings) Windows. o (tuple) hash() __hash__ IP IPRange __eq__ ( Python). o (unit test) (code coverage). 33 - o CIDR CIDR 35 - o ( Python socket.has_ipv6 False ) 36 - o netaddr.CIDR CIDR (default route) 37 - o AND IP 38 - o : Addr.__nonzero__ 39 - o CIDR.abbrev_to_verbose() (classful netmask) : 0.6.1 o IEEE IANA . o IPv4 IANA ( 2009-03-11) o (Internet Multicast Addresses) ( 2009-03-17) o OUI IAB IEEE ( 2009-04-13) o get_latest_files() netaddr.eui netaddr.ip . Issue 32 - o Addr.__ne__ : 0.6.1 : 0.6 o COPYRIGHT netaddr. o Python 2.3.x 2.4.x . o Python 2.3 . o @property @staticmethod reversed() sorted() . o netaddr Python < 2.4.x RuntimeError . o IP() EUI() (AT_*) . IPv4/IPv6 . EUI-48/EUI-64 . . o IPv6 EUI.ipv6_link_local() /64 . o (IPRange CIDR Wildcard) () . . o CIDR.abbrev_to_verbose() IPv4 ( ) . IPv4 /32 . o CIDR 'expand_abbrev' . o CIDR.summarize() IP CIDR . ! o previous() next() CIDR CIDR CIDR . CIDR 192.0.2.0/24 previous 192.0.1.0/24 next 192.0.3.0/24 . ( 1 ). o supernet() CIDR CIDR prefixlen . o (fallback) socket . o (uppercase) Strategy word_fmt (word_fmt='%X'). FIXED Issue 23 - o IPv6 / IPv4 FIXED Issue 24 - o CIDR.subnet() fmt FIXED Issue 29 - o count CIDR.subnet FIXED Issue 30 - o Python 2.3 FIXED Issue 31 - o : 0.6 : 0.5.x o (Namespace) :- o netaddr.eui IEEE OUI IAB (lookup) . o netaddr.ip IPv4 IPv6 (multicast) IPv4 IANA . o netaddr.core netaddr.eui netaddr.ip . : netaddr . MAC/EUI IP CIDR Wildcard . netaddr.core . ( 0.7 ) netaddr.address netaddr.strategy . netaddr . netaddr.__all__ . o IEEE IANA o IP() EUI() info() . IANA IEEE netaddr ( ) . docstring . netaddr . o EUI() OUI() IAB() . EUI.info() . API netaddr . o NotRegisteredError EUI IEEE . o Addr() o . o AddrRange() o IPRange() . AddrRange() . o IPRange() o CIDR() Wildcard(). o << >> iprange() cidrs() wildcard() . IPRange('x', 'y').cidrs() CIDR IP . o IPRange() issupernet() issubnet() adjacent() overlaps(). o data_flavour() () format() . o IP() o is_netmask() is_hostmask() ! o wildcard() iprange() netmask / . o (copy constructor) ipv4() ipv6() prefixlen IPv6 IPv6 IPv4 IPv4 . o is_loopback() is_private() is_link_local() is_ipv4_mapped() is_ipv4_compat() . o bin() IP bin() ('0bxxx') Python 2.6.x . o packed() IP . o nrange() o Addr() IP() . o CIDR() o 'strict_bitmask' CIDR 'strict' ( ). o Cisco ACL ( hostmask). IP() . netmask . (generator) subnet() CIDR CIDR CIDR /24 /25 /32 . o span() IP IPRange CIDR / Wildcard CIDR ('spans'). CIDR () . . . o IPv6 (broadcast address) network() broadcast() CIDR . . o network() broadcast() hostmask() netmask() property() (read-only) . o MAC IPv4 o EUI IP . . . o __repr__() o repr() from netaddr import * . . netaddr . o 'klass' 'fmt' (format) o 'format callable' . 'klass' Python (callables) . o (unit tests). o API . o . netaddr . o egg Python setuptools. o . (Specific bug fixes addressed in this release) o IPv6 inet_ntop() inet_pton() socket ( ). (Experimental Features) o (bitwise) IP o . IP IP . o IPRangeSet() (). o IP() IPRange() CIDR() Wildcard() . IP any_match() all_matches() min_match() max_match() . o . . 0.7 . : o . IPv6 IPv4 IPv6Strategy. (unit test) . o PrefixLenDescriptor() CIDR.prefixlen CIDR.first CIDR.last . . o IP.hostname() DNS None . : 0.5.1 : o CIDR TypeError . . o CIDR.netmask() CIDR.hostmask() . . : 0.5 : 0.4.x o netaddr (descriptor) . . CIDR Wildcard - . o () Addr AddrRange . IPv4 IPv6 EUI-48 EUI-64 . () AddrRange ! o () Addr AddrRange AttributeError False . o (workaround) inet_aton('255.255.255.255') socket . Python 2.4.x PowerPC MacOS X . socket ( Google App Engine) . o Exception strategy ValueError ( 0.4 ). o __hash__() Addr AddrStrategy . IP CIDR Wildcard (sets) . - . o __ne__() Addr AddrRange . o << >> ('Law of Demeter') () Addr AddrRange :- obj.addr_type # 0.5 onwards strategy :- obj.strategy.addr_type # 0.4 and earlier o AT_DESCR AT_NAMES . (imports) . Addr o setvalue() Addr __setattr__() . IP o masklen prefixlen IP . prefixlen netmask IP . netmask_bits() is_netmask() True IP . prefixlen /32 is_netmask() True ValueError . o family() IP prefixlen . o IP . is_multicast() is_unicast() IP ipv4() ipv6() IPv4 <-> IPv6 (copy constructors) . o DNS (.) . o hostname() IP DNS . o __str__() IP IPv4 /32 IPv6 /128 . . AddrRange o AddrRange () Addr . self.start_addr self.stop_addr self.first self.last obj.first() obj.last() . self.first self.last strategy . . () Addr ( klass) obj[0] obj[-1] obj.first() obj.last() . o () AddrRange __iadd__() __isub__() . CIDR Wildcard ('slide'). o _retval() data_flavour() - ;-) . . CIDR o CIDR strict_bitmask=False . True ( ) . o CIDR. 224.0.0.0 /8 /4 . o CIDR CIDR . CIDR . CIDR ;-) o abbrev_to_cidr() CIDR.abbrev_to_verbose() . . Wildcard o Wildcard Wildcard.is_valid() Wildcard wildcard . : 0.3.x o Exception TypeError ValueError AddrFormatError AddrConversionError . o IP (subnet prefix) . CIDR ( ) . o CIDR CIDR ValueError . o CIDR CIDR (classful) . 10 10/8 192.168/16 . CIDR IPv4 . o __repr__() netaddr . o CIDR Wildcard :- o CIDR -> Wildcard o Wildcard -> CIDR o docstring epydoc API. o pylint. o netaddr __version__ setup.py . o setup.py MANIFEST.in. o Exception strategy.py __init__.py . o __all__ * import netaddr address strategy . o (line-ending) . (COPYRIGHT) netaddr . netaddr (c) 2008 David P. D. Moss (c) 2020 netaddr BSD . LICENSE . IANA (Internet Assigned Numbers Authority) netaddr IANA . IANA ( ) . IANA netaddr API . README ..SS "IEEE ( )" netaddr IEEE . IEEE ( ) () . : IEEE netaddr API . . README . (LICENSE) netaddr . netaddr (COPYRIGHT AND LICENSE) Copyright (c) 2008 David P. D. Moss Portions Copyright (c) 2020 netaddr contributors : o . o / . o David P. D. Moss . << >> ("AS IS") . ( ) ( ) . (AUTHORS) o David P. D. Moss ( ) o Stefan Nordhausen () o Jakub Stasiak () BSD ( <> ). (CONTRIBUTORS) netaddr David P. D. Moss Jakub Stasiak . BSD . netaddr . ( ) . . Vincent Bernat Sebastien Douche John Eckersberg Yi-Jheng Lin Clay McClure Duncan McGreggor Stefan Nordhausen Brian F. Peters James William Pye Chaitan Rogers Victor Stinner Andrew Stromnov netaddr . :- a. . Python Cookbook : "Formatting Integers as Binary Strings" Python Cookbook 2d ed. (O'Reilly Media 2005) ISBN 0596-00797-3 Alex Martelli, Anna Martelli Ravenscroft and David Ascher b. ASPN Cookbook : "Integer set type" Heiko Wundram Guido van Rossum Python ..SH " (INDICES AND TABLES)" o <> o <> (AUTHOR) David P. D. Moss (COPYRIGHT) 2008 David P. D. Moss netaddr 1.3.0 December 14, 2025 NETADDR(1)