NETADDR(1)
β¨ NAME β¨
so like, welcome to netaddr(1) bestie π β this is the netaddr documentation, and honestly? it's kind of iconic.
netaddr is a Python library and a CLI tool <> for representing and manipulating layer 3 (IP) and layer 2 (MAC) network addresses. no cap, that's the whole vibe.
here's everything netaddr has your back on:
Layer 3 addresses π
- IPv4 and IPv6 addresses, subnets, masks, prefixes
- iterating, slicing, sorting, summarizing and classifying IP networks
- dealing with various ranges formats (CIDR, arbitrary ranges and globs, nmap)
- set based operations (unions, intersections etc) over IP addresses and subnets
- parsing a large variety of different formats and notations
- looking up IANA IP block information
- generating DNS reverse lookups
- supernetting and subnetting
Layer 2 addresses π
- representation and manipulation MAC addresses and EUI-64 identifiers
- looking up IEEE organisational information (OUI, IAB)
- generating derived IPv6 addresses
netaddr's documentation uses the DiΓ‘taxis approach to technical documentation authoring β the link is https://diataxis.fr/ if you wanna go look β and it's organized like so:
- Tutorials
<>take you on a step-by-step journey through some of the netaddr's features. Start here if you're new to netaddr. - How-to guides
<>are recipes and provide steps to address common problems and use-cases. - Reference
<>contains technical description of various parts of netaddr machinery (including the API Reference<>).
πΈ TUTORIALS πΈ
the pages in this section take you on a step-by-step journey through some of the netaddr's features.
start here if you're new to netaddr. seriously. it's giving "beginner friendly" and i mean that as the highest compliment π
π¦ Tutorial 1: IP Addresses, Subnets and Ranges π¦
first of all, you need to pull the various netaddr classes and functions into your namespace, like so:
>>> from netaddr import *
Note: do this for the purpose of this tutorial only, bestie. in your own code you should be explicit about the classes, functions and constants you import so you don't get name clashes. learn from my chaos π
we also import the standard library module pprint to help format our output.
>>> import pprint
β Basic operations β
the following IPAddress object represents a single IP address.
>>> ip = IPAddress('192.0.2.1')
>>> ip.version
4
the repr() call returns a Python statement that can be used to reconstruct an equivalent IP address object state from scratch when run in the Python interpreter. it's literally a little recipe for rebuilding your address π«Ά
>>> repr(ip)
"IPAddress('192.0.2.1')"
>>> ip
IPAddress('192.0.2.1')
access in the string context returns the IP object as a string value.
>>> 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 π₯
you can view an IP address in various other formats. it's giving versatility, it's giving range π
>>> 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 objects are used to represent subnets, networks or VLANs that accept CIDR prefixes and netmasks.
>>> 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
in this case, the network and broadcast address are the same, akin to a host route. tiny network. one whole address. she's lowkey doing the most with the least π
>>> 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
and finally, this IPNetwork object represents an IP address that belongs to a given IP subnet.
>>> 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
internally, each IPNetwork object only stores 3 values:
- the IP address value as an unsigned integer
- a reference to the IP protocol module for the IP version being represented
- the CIDR prefix bitmask
all the other values are calculated on-the-fly on access. efficient queen behavior, we love to see it π
it is possible to adjust the IP address value and the CIDR prefix after object 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')
the prefix length can also be changed by specifying a 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')
there is also a property that lets you access the true CIDR address, which removes all host bits from the network address based on the CIDR subnet prefix.
>>> ip = IPNetwork('192.0.2.1/23')
>>> ip.cidr
IPNetwork('192.0.2.0/23')
this is handy for specifying some networking configurations correctly. trust, you'll want this one in your back pocket π
if you want to access information about each of the various IP addresses that form the IP subnet, this is available by performing pass through calls to sub methods of each IPAddress object.
for example, if you want to see a binary digit representation of each address, you can do the following.
>>> 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 support π§
full support for IPv6 is provided. let's try a few examples:
>>> 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'
bit-style output isn't as quite as friendly as hexadecimal for such a long numbers, but here's the proof that it works!
>>> ip.ip.bits()
'1111111010000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:1101111010101101:1011111011101111'
here are some networking details for an IPv6 subnet.
>>> 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'))
π Interoperability between IPv4 and IPv6 π
it is likely that with IPv6 becoming more prevalent, you'll want to be able to interoperate between IPv4 and IPv6 address seamlessly. like, fr fr, at some point you're gonna have to translate between the eras π
here are a couple of methods that help achieve this.
π IPv4 to IPv6 conversion π
>>> 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 to IPv4 conversion π
>>> 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')
Note: that the IP object returns IPv4 "mapped" addresses by default in preference to IPv4 "compatible" ones. this has been chosen purposefully, since the latter form has been deprecated (see RFC 4291 for details). so like, don't use the deprecated one unless you have a really good reason, bestie π
π«Ά List operations π«Ά
if you treat an IPNetwork object as if it were a standard Python list object, it will give you access to a list of individual IP address objects. this, of course, is illusory, and they are not created until you access them. sneaky? yes. efficient? also yes π
>>> ip = IPNetwork('192.0.2.16/29')
accessing an IP object using the list() context invokes the default generator, which returns a list of all IP objects in the range specified by the IP object's subnet.
>>> 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')]
the length of that list is 8 individual IP addresses.
>>> len(ip)
8
π Indexing π
you can use standard index access to IP addresses in the subnet.
>>> ip[0]
IPAddress('192.0.2.16')
>>> ip[1]
IPAddress('192.0.2.17')
>>> ip[-1]
IPAddress('192.0.2.23')
π¦ Slicing π¦
you can also use list slices on IP addresses in the subnet.
>>> ip[0:4]
<generator object ...>
the slice is a generator function. this was done to save time and system resources, because some slices can end up being very large for certain subnets! girl math says don't build a giant list you're not even gonna finish π
here is how you'd access all elements in a slice.
>>> 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 is also supported.
>>> 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 reversal.
>>> list(ip[-1::-1])
[IPAddress('192.0.2.23'), IPAddress('192.0.2.22'), ..., IPAddress('192.0.2.17'), IPAddress('192.0.2.16')]
use of generators ensures working with large IP subnets is efficient.
>>> 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
in IPv4 networks you only usually assign the addresses between the network and broadcast addresses to actual host interfaces on systems. like, those two edge addresses are reserved, so don't be out here assigning them to a host π
here is the iterator provided for accessing these IP addresses:
>>> 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
β¨ Sorting IP addresses and networks β¨
Okay so being able to sort IP addresses and networks canonically? Genuinely one of the most common and useful things ever. Here's how sorting works with individual addresses. π
>>> 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')]
And for convenience, you can sort IP subnets at the same time as addresses β and they can be combinations of IPv4 and IPv6 addresses at the same time too (IPv4 addresses and networks appear before IPv6 ones). bestie that's literally so convenient π
>>> 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')]
Notice how overlapping subnets also sort in order from largest to smallest. tiny detail, huge slay πΈ
β¨ Summarizing list of addresses and subnets β¨
Another wildly useful operation is being able to summarize groups of IP subnets and addresses β merging them together where possible so you end up with the smallest possible list of CIDR subnets. Obsessed.
You do this in netaddr using the cidr_merge() function.
First we create a list of IP objects that contains a good mix of individual addresses and subnets, along with some string-based IP address values for good measure. And to make things more interesting, some IPv6 addresses get thrown in as well. π
>>> 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')]
Useful, isn't it? π¦
β¨ Supernets and subnets β¨
Super common scenario: you've got a big CIDR subnet and you wanna split it up into multiple smaller component blocks so you can actually manage your network allocations, firewall rules etcc β and netaddr gives you the tools you need for exactly that. π«Ά
Here we take a large /16 private class B network block and split it up into a set of smaller 512 sized blocks.
>>> ip = IPNetwork('172.24.0.0/16')
>>> ip.subnet(23)
<generator object ...>
And once again, this method produces an iterator β because of the possibility of a large number of return values depending on the subnet size you specify. no cap, could be a whole lot of them π
>>> 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')]
It's also possible to retrieve the list of supernets that a given IP address or subnet belongs to. You can specify an optional limit too.
>>> 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')]
Here we return a list rather than a generator, because the potential list of values is of a predictable size β no more than 31 subnets for an IPv4 address and 127 for IPv6. love that for us β
β¨ Support for non-standard address ranges β¨
CIDR is a super useful way to describe networks succinctly, but it's often necessary (especially with IPv4, which literally predates the CIDR specification) to be able to generate lists of IP addresses that have an arbitrary start and end address that don't fall on strict bit mask boundaries.
The iter_iprange() function lets you do exactly that. π
>>> 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')]
And it's equally nice to know what the actual list of CIDR subnets is that would correctly cover this non-aligned range of addresses.
Here cidr_merge() comes to the rescue once more. π§
>>> 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')]
β¨ Dealing with older IP network specifications β¨
Before the CIDR specification existed, it was common to infer the netmask of an IPv4 address based on its first octet using a set of classful rules (first defined in RFC 791).
You come across references to them all the time in various RFCs, and they're well supported by a number of software libraries. So for completeness β rather than leaving out this important (but now somewhat historical) set of rules β they're supported via the cryptically named cidr_abbrev_to_verbose() function. iykyk π
Here's an example of these rules for the whole of the IPv4 address space.
>>> 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 address categorisation β¨
IP addresses fall into several categories β and not all of them are suitable for assignment as host addresses. main character energy only for some of them, honestly π
Unicast
>>> IPAddress('192.0.2.1').is_unicast()
True
>>> IPAddress('fe80::1').is_unicast()
True
Multicast
Used to identify multicast groups (see RFC 2365 and 3171 for more info).
>>> IPAddress('239.192.0.1').is_multicast()
True
>>> IPAddress('ff00::1').is_multicast()
True
Reserved
Addresses in reserved ranges are not available for general use. π«
>>> IPAddress('253.0.0.1').is_reserved()
True
Netmasks
A bitmask used to divide an IP address into its network address and host address.
>>> IPAddress('255.255.254.0').is_netmask()
True
Hostmasks
Similar to a netmask but with all the bits flipped the opposite way.
>>> IPAddress('0.0.1.255').is_hostmask()
True
Loopback
These addresses are used internally within an IP network stack, and packets sent to these addresses are not distributed via a physical network connection.
>>> IPAddress('127.0.0.1').is_loopback()
True
>>> IPAddress('::1').is_loopback()
True
β¨ Comparing IP addresses β¨
IPAddress objects can be compared with each other. But since an IPAddress object can represent both an individual IP address and an implicit network, it really pays to get both sides of your comparison into the same terms before you compare them β otherwise you get odd results. trust me on this one π
Here are some comparisons of individual IP addresses to get the ball rolling.
>>> 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
Now let's try something a little more interesting.
>>> IPNetwork('192.0.2.0/24') == IPNetwork('192.0.2.112/24')
True
Hmmmmmmmm... looks a bit odd, doesn't it? That's because by default, IP objects compare their subnets (or lower and upper boundaries) rather than their individual IP address values.
The solution to this situation is very simple. Knowing this default behaviour, just be explicit about exactly which portion of each IP object you'd like to compare, using pass-through properties. π
>>> 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
That's more like it. You can also be explicit about comparing networks in this way if you so wish (although it's not strictly necessary).
>>> IPNetwork('192.0.2.0/24').cidr == IPNetwork('192.0.2.112/24').cidr
True
Armed with this information, here are some examples of network comparisons.
>>> 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
This will inevitably raise questions about comparing IPAddress (scalar) objects and IPNetwork (vector) objects with each other (or at least, it should).
Here's how netaddr chooses to address this situation.
>>> IPAddress('192.0.2.0') == IPNetwork('192.0.2.0/32')
False
>>> IPAddress('192.0.2.0') != IPNetwork('192.0.2.0/32')
True
An IP network or subnet is different from an individual IP address, and therefore cannot be (directly) compared.
If you want to compare them successfully, you must be explicit about which aspect of the IP network you wish to match against the IP address in question.
You can use the index of the first or last address if it's a /32, like so:
>>> 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
You can also use the base address if that's what you wish to compare:
>>> 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
While this may seem a bit pointless at first, netaddr strives to keep IP addresses and networks separate from one another while still allowing reasonable interoperability. it's giving healthy boundaries π
β¨ DNS support β¨
A super common administrative task is generating reverse IP lookups for DNS. And it's particularly arduous for IPv6 addresses. π©
Here's how you do this using an IPAddress object's reverse_dns() method.
>>> 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.'
Heads up bestie: ip6.int is not used here, because it has been deprecated (see RFC 3152 for details). don't use it, fr fr π«
Non standard address ranges β¨
okay so real talk: CIDR is kind of a newcomer, and IP version 4 has a reeeally long history, so you're absolutely gonna bump into systems and documentation that talk about IP address ranges in formats that are not CIDR. Converting from those arbitrary range types to CIDR and back again? Not a fun task, ngl, it's giving busywork π. Luckily netaddr has your back and built two purpose-built classes just so this job is easy for you. π«Ά
Arbitrary IP address ranges
You can represent an arbitrary IP address range using a lower bound and an upper bound address, in the form of an IPRange object. So simple.
>>> r1 = IPRange('192.0.2.1', '192.0.2.15')
>>> r1
IPRange('192.0.2.1', '192.0.2.15')
You can iterate across these ranges and index into them just like an IPNetwork object. Indexing rights, bestie. π
And β importantly β you can also convert it to its CIDR equivalent:
>>> 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')]
Here's how individual IPRange and IPNetwork compare. This is the good stuff:
>>> 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
You may also want to compare an IP range against a list of IPAddress and IPNetwork objects. Cute idea! Let's see:
>>> 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
Oops! π Not quite what we were looking for or expecting, bestie. The range and the list are just not the same type of thing.
The way to do this is to get either side of the comparison operation into the same terms. Then it slays:
>>> list(r1) == addrs
True
That's more like it. π
The same goes for IPNetwork objects:
>>> 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
The above works if the list you're comparing contains one type or the other β but what if you've got a mixed list of IPAddress, IPNetwork and string addresses? π
Time for some slightly more powerful operations. Let's make use of a brand-new class for dealing with groups of IP addresses and subnets: the IPSet class. Meet the main character:
>>> 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
Let's remove one of the elements from one of the IPSet objects and see what happens π:
>>> s2.pop()
IPNetwork('...')
>>> s1 == s2
False
This is perhaps a somewhat contrived example, but it just shows you some of the capabilities on offer. No cap.
See the IPSet tutorial Tutorial 3: Working with IP sets <> for more details on that class.
IP Glob ranges π¦
netaddr also supports a user-friendly way of specifying IP address ranges using a "glob" style syntax. It's giving shell wildcards, and we're obsessed.
Note: At present only IPv4 globs are supported.
>>> IPGlob('192.0.2.*') == IPNetwork('192.0.2.0/24')
True
>>> IPGlob('192.0.2.*') != IPNetwork('192.0.2.0/24')
False
And because IPGlob is a subclass of IPRange, all of the same operations apply. Inheritance ate, honestly. π
Tutorial 2: MAC addresses π
First of all you need to pull the various MAC related classes and functions into your namespace. Grabby hands:
Note: Do this for the purpose of this tutorial only. In your own code, you should be explicit about the classes, functions and constants you import to avoid name clashes.
>>> from netaddr import *
You can reasonably safely import everything from the netaddr namespace, because care has been taken to only export the necessary classes, functions and constants.
But always hand-pick your imports if you're unsure about possible name clashes. Fr fr, protect your namespace. π«Ά
Basic operations
Instances of the EUI class are used to represent MAC addresses.
>>> mac = EUI('00-1B-77-49-54-FD')
Standard repr() access returns a Python statement that can reconstruct the MAC address object from scratch if executed in the Python interpreter. Look at her go:
>>> mac
EUI('00-1B-77-49-54-FD')
Accessing the EUI object in the string context:
>>> str(mac)
'00-1B-77-49-54-FD'
>>> '%s' % mac
'00-1B-77-49-54-FD'
Here are a few other common properties. Little field trip through the object's internals β¨:
>>> str(mac), str(mac.oui), mac.ei, mac.version
('00-1B-77-49-54-FD', '00-1B-77', '49-54-FD', 48)
Numerical representations π’
You can view an individual MAC address in various other formats. She contains multitudes:
>>> int(mac) == 117965411581
True
>>> hex(mac)
'0x1b774954fd'
>>> oct(mac)
'0o1556722252375'
>>> mac.bits()
'00000000-00011011-01110111-01001001-01010100-11111101'
>>> mac.bin
'0b1101101110111010010010101010011111101'
Formatting π
It is very common to see MAC addresses in many different formats other than the standard IEEE EUI-48. Like, everywhere.
The EUI class constructor handles all these common forms, which is honestly such a relief.
>>> EUI('00-1B-77-49-54-FD')
EUI('00-1B-77-49-54-FD')
IEEE EUI-48 lowercase format:
>>> EUI('00-1b-77-49-54-fd')
EUI('00-1B-77-49-54-FD')
Common UNIX format:
>>> EUI('0:1b:77:49:54:fd')
EUI('00-1B-77-49-54-FD')
Cisco triple hextet format:
>>> 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')
Bare MAC addresses (no delimiters, raw vibes):
>>> EUI('001b774954fd')
EUI('00-1B-77-49-54-FD')
>>> EUI('01B774954FD')
EUI('00-1B-77-49-54-FD')
PostreSQL format (found in documentation):
>>> EUI('001B77:4954FD')
EUI('00-1B-77-49-54-FD')
It's equally possible to specify a selected format for your MAC string output in the form of a 'dialect' class. Its use is similar to the dialect class used in the Python standard library csv module. iykyk.
>>> 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')
You can, of course, create your own dialect classes to customise the MAC formatting if the standard ones don't suit your needs. Be the author of your own destiny β¨
Here's a tweaked UNIX MAC dialect that generates uppercase, zero-filled 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')
Querying organisational information π
EUI objects provide an interface to the OUI (Organisationally Unique Identifier) and IAB (Individual Address Block) registration databases available from the IEEE. Yes, the real database. Yes, live.
Here's how you query an OUI with the EUI interface:
>>> 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'
You can also use OUI objects directly, without going through the EUI interface. Independent queen behaviour.
A few OUI records have multiple registrations against them. I'm not sure if this is recording historical information or just a quirk of the IEEE registration process. π€·ββοΈ Either way, here's how you access them individually by specifying an index number:
>>> 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')
Here's how you query an IAB with the EUI interface:
>>> 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}
Tutorial 3: Working with IP sets πΈ
First of all you need to pull the various netaddr classes and functions into your namespace.
Note: Do this for the purpose of this tutorial only. In your own code, you should be explicit about the classes, functions and constants you import to avoid name clashes.
>>> from netaddr import *
Creating IP sets
Here's how to create IP sets. Buckle up, bestie.
An empty set. Nothing in it. Empty girl autumn π:
>>> IPSet()
IPSet([])
>>> IPSet([])
IPSet([])
>>> len(IPSet([]))
0
You can specify either IP addresses and networks as strings. Alternatively, you can use IPAddress, IPNetwork, IPRange or other IPSet objects. Mix and match, she's flexible:
>>> 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'])
You can iterate over all the IP addresses that are members of the IP set.
>>> 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
see how it just walks them in order, v4 block first then the v6-mapped block? iterating an IPSet is genuinely so satisfying, no cap π
π Adding and removing set elements π
okay so IPSet has .add() and .remove() and they take single addresses, ranges, whatever β and the set re-crunches itself into the tidiest possible CIDRs after every change. watch:
>>> 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'])
literally the set ate a whole IPRange and spat out 10.0.0.0/24, then we carved away from 10.0.0.128 to 10.10.10.10 and it healed itself back into 10.0.0.0/25. that's the whole vibe. π¦
πΈ Set membership πΈ
here's a simple arbitrary IP address range:
>>> iprange = IPRange('192.0.1.255', '192.0.2.16')
and we can peek at the CIDR networks that can exist within that defined range:
>>> iprange.cidrs()
[IPNetwork('192.0.1.255/32'), IPNetwork('192.0.2.0/28'), IPNetwork('192.0.2.16/32')]
here's an IP set:
>>> ipset = IPSet(['192.0.2.0/28'])
now the main character moment β iterate over the IP addresses in that arbitrary range and check each one with in:
>>> 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
the Falses on the ends are not a bug bestie, they're just the two /32 edges sitting outside the /28 π
β¨ More exotic IPSets β¨
>>> 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
yes 0.0.0.0/0 is everything IPv4 β every v4 address and every v4 network is in it. ::1 is not, because that's a v6 address and this set is v4-only. boundaries, respect them. π«Ά
>>> 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
10.0.0.42/31 is not in there because a /31 covers 10.0.0.42 and 10.0.0.43, and 10.0.0.43 is not in the set. whole network or nothing, periodt. π
π Unions, intersections and differences π
here are some union operations on IPSet objects:
>>> 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'])
notice how 192.0.2.0/24 + 192.0.3.0/24 collapses into 192.0.2.0/23 but 192.0.4.0/24 can't join the party? that's the summarisation doing its thing. it only merges what actually merges π
here's union, intersection and symmetric difference all playing at the same time:
>>> 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'])
the way evens & odds is just IPSet([]) β empty, bestie, they don't share a single address π and evens | odds gives back the whole /24, as it should.
π§ Supersets and subsets π§
IPSet can also test whether one group of address ranges fits inside another group of address ranges:
>>> 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
yes bestie, issubset and issuperset go both ways and they will contradict each other if you ask them to π
here's a more complete example using various well known IPv4 address ranges:
>>> 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
let's see what we've got:
>>> 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
cidr[0] is the first address, cidr[-1] is the last β indexing an IPNetwork like that is such a serve, honestly π
and if we XOR the whole space against what came out, we get the unavailable chunk right back:
>>> 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'])
π¦ Combined IPv4 and IPv6 support π¦
in keeping with netaddr's pragmatic approach, you are free to mix and match IPv4 and IPv6 within the same data structure. no separation anxiety, they can sit together:
>>> 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 and IPv6 set union π
>>> 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'])
same answer both ways, as union should be, we love commutativity π«Ά
π set intersection π
>>> s1 & s2
IPSet(['192.0.2.2/32', '::ffff:192.0.2.2/128'])
only the .2s survive. iconic.
π₯ set difference π₯
>>> 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'])
order matters here bestie, s1 - s2 is not s2 - s1 π
β set symmetric difference β
>>> 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'])
everything in exactly one of them β the .2s got voted off the island β¨
π Disjointed IP sets π
>>> 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
isdisjoint is literally just "did the intersection come back empty" with extra attitude π
πΈ Updating an IP set πΈ
as with a normal Python set you can also update one IP set with the contents of another:
>>> 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([])
update() takes a set, a list, an IPRange, whatever β and clear() wipes it to IPSet([]) like it never happened π
π Removing elements from an IP set π
removing an IP address from an IPSet will split the CIDR subnets within it into their constituent parts. yes, it shatters them. here we create a set representing the entire IPv4 address space:
>>> s1 = IPSet(['0.0.0.0/0'])
>>> s1
IPSet(['0.0.0.0/0'])
then we strip off the last address:
>>> s1.remove('255.255.255.255')
leaving us with:
>>> 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
one address removed = 32 CIDRs now, descending in size. that's the shattering, bestie, it's giving cascade π
let's check the result using the cidr_exclude function:
>>> list(s1.iter_cidrs()) == cidr_exclude('0.0.0.0/0', '255.255.255.255')
True
next, let's remove the first address from the original range:
>>> s1.remove('0.0.0.0')
and this fractures the CIDR subnets even further.
>>> 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
You can literally keep doing this forever, bestie, but be aware that large IP sets can take up a lot of memory if they contain many thousands of entries. Like, your RAM is gonna feel it π
Adding elements to an IP set
Let's fix up the fractured IP set from the previous section by re-adding the IP addresses we removed. Glow-up time β¨
>>> 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'])
Getting better. We're so back π
>>> 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
Add back the other IP address.
>>> s1.add('0.0.0.0')
And we're back to our original address. Iconic behaviour, no notes π
>>> s1
IPSet(['0.0.0.0/0'])
Convert an IP set to an IP Range
Sometimes you may want to convert an IPSet back to an IPRange. Totally valid, we support the journey π«Ά
>>> s1 = IPSet(['10.0.0.0/25', '10.0.0.128/25'])
>>> s1.iprange()
IPRange('10.0.0.0', '10.0.0.255')
This only works if the IPSet is contiguous. Contiguous is the vibe check here.
>>> 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 "<stdin>", line 1, in <module>
ValueError: IPSet is not contiguous
If it is not contiguous, you can still convert the IPSet, but you will get multiple IPRanges. Not a flop, just a different format π
>>> 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 objects
As with all other netaddr classes, you can use pickle to persist IP sets for later use. Save it, bestie, future you will be obsessed π
>>> 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
Compare IPSet objects
>>> x = IPSet(['fc00::/2'])
>>> y = IPSet(['fc00::/3'])
>>> x > y
True
>>> x < y
False
>>> x != y
True
π HOW-TO GUIDES π
The pages in this section are recipes and provide steps to address common problems and use-cases. Think of it as the netaddr cookbook, and every recipe slays π
How to install netaddr
Various Linux distributions make it available via their package managers. Convenient? Very.
Installing from the Python Package Index
The easiest way to install netaddr is to use pip. Literally the main character of installers.
Download and install the latest version from PyPI - <https://pypi.org/project/pip> and run the following command
pip install netaddr
If you want better the Interactive shell <#interactive-shell> experience you can install the extra IPython dependency like
pip install 'netaddr[nicer-shell]'
or install IPython directly
pip install ipython
Installing using your Linux distribution package manager
Various Linux distributions make netaddr available via their package managers.
Note: The netaddr versions provided by Linux distributions may be outdated. Like, check before you commit, bestie π
Refer to your distribution's documentation for installation instructions.
Example commands:
# Debian, Ubuntu
sudo apt install python3-netaddr
# Fedora
# Base installation
sudo dnf install python3-netaddr
# The CLI tool
sudo dnf install python3-netaddr-shell
Installing from a source package
Download the latest release tarball/zip file and extract it to a temporary directory or clone the repository into a local working directory.
Install the local package:
pip install .
This automatically places the required files in the lib/site-packages directory of the Python version you used to run the setup script, may also be part of a virtualenv or similar environment manager. Cute, right? β¨
π REFERENCE π
The pages in this section contain technical description of various parts of netaddr machinery. Yes, the deep lore.
Compatibility
Supported Python versions
netaddr supports the following Python versions (CPython and PyPy):
- 3.7
- 3.8
- 3.9
- 3.10
- 3.11
- 3.12
Support for the following versions has been removed in 1.0.0:
- 2.7
- 3.5
- 3.6
Support deprecated and scheduled to be removed in netaddr 2:
- 3.7
Heads up bestie, 3.7 is on the way out β deprecated and scheduled to be removed in netaddr 2 π
Supported operating systems
The library is operating system-independent. It truly does not care where you run it, it's giving universal icon π
Supported hardware architectures
The library is hardware architecture-independent. Same energy, no architecture discourse.
π API Reference π
This page documents netaddr's public API. Only things explicitly mentioned in this documentation are supported and considered part of the public API.
Any of the following is considered private and unsupported. Like, do not touch, it's not for you π ββοΈ
- Anything within any of the netaddr submodules (
from netaddr.X import Y) - Anything with a name started with a single underscore (
_X) - Anything not explicitly documented as part of the public API
IP Class Hierarchy
Here the class hierarchy for IP related classes
+---------+ +---------+
| 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 |
+--------+
Constants
The following constants are used by the various flags arguments on netaddr class constructors.
netaddr.INET_PTONβ Useinet_pton()semantics instead ofinet_aton()when parsing IPv4. See theIPAddress.__init__()documentation for details. Changed in version 1.0.0: Started rejecting leading zeros regardless of the platform (it was previously allowed on some).netaddr.INET_ATONβ Useinet_aton()semantics when parsing IPv4. See theIPAddress.__init__()documentation for details. Added in version 0.10.0.netaddr.ZEROFILLβ Remove any preceding zeros from IPv4 address octets before parsing. See theIPAddress.__init__()documentation for details.netaddr.NOHOSTβ Remove any host bits found to the right of an applied CIDR prefix. See theIPNetwork.__init__()documentation for details.
Custom Exceptions
IP addresses
An IP address is a virtual address used to identify the source and destination of (layer 3) packets being transferred between hosts in a switched network. This library fully supports both IPv4 and the new IPv6 standards.
The IPAddress class is used to identify individual IP addresses. One address, one icon, one main character π
IPv6 formatting dialects
The following dialect classes can be used with the IPAddress.format method.
IP networks and subnets
The IPNetwork class is used to represent a group of IP addresses that comprise a network/subnet/VLAN containing hosts.
Nowadays, IP networks are usually specified using the CIDR format with a prefix indicating the size of the netmask. In the real world, there are a number of ways to express a "network"" and so the flexibility of the IPNetwork class constructor reflects this. So many ways, so many vibes πΈ
Arbitrary IP address ranges
netaddr was designed to accommodate the many different ways in which groups of IP addresses and IP networks are specified, not only in router configurations but also less standard but more human-readable forms found in, for instance, configuration files.
Here are the options currently available.
bounded ranges
A bounded range is a group of IP addresses specified using a start and end address forming a contiguous block. No bit boundaries are assumed but the end address must be numerically greater than or equal to the start address. Like, the end cannot be less than the start, that's just logic, bestie π§
IP glob ranges
A very useful way to represent IP network in configuration files and on the command line for those who do not speak CIDR.
The IPGlob class is used to represent individual glob ranges.
globbing functions
It is also very useful to be able to convert between glob ranges and CIDR and IP ranges. The following function enable these various conversions. Glow-up via conversion, we love to see it β¨
nmap ranges
nmap is a well known network security tool. It has a particularly flexible way of specifying IP address groupings.
Functions are provided that allow the verification and enumeration of IP address specified in this format.
IP sets
When dealing with large numbers of IP addresses and ranges it is often useful to manipulate them as sets so you can calculate intersections, unions and differences between various groups of them.
The IPSet class was built specifically for this purpose. Set math but make it fashion π
IP functions and generators
The following are a set of useful helper functions related to the various format supported in this library. Little helpers, absolute sweethearts π«Ά
MAC addresses and the IEEE EUI standard
A MAC address is the 48-bit hardware address associated with a particular physical interface on a networked host. They are found in all networked devices and serve to identify (layer 2) frames in the networking stack.
The EUI class is used to represents MACs (as well as their larger and less common 64-bit cousins).
MAC formatting dialects
The following dialects are used to specify the formatting of MAC addresses. Pick your fave format, they're all valid π
π Validation functions π
This is the validation corner of the docs β the place where you check whether the stuff you typed is actually, y'know, real. And right next to it lives the silliest little section in the whole package, which honestly? iconic.
π A bit of fun π
Who said networking was all about being serious? It's always good to lighten up and have a bit of fun. π
Let's face it, no networking library worth its salt would be complete without support for RFC 1924 β <http://www.ietf.org/rfc/rfc1924> :-) like, that's just science bestie.
π₯οΈ CLI tool π₯οΈ
The netaddr package includes a netaddr CLI application. yes, the package and the command have the same name, it's giving main character energy.
β οΈ Note: the tool is meant to be used by humans. Its interface should not be considered stable. Exercise caution when using it in any kind of programmatic context (read: scripting). If you want a stable interface use the programmatic API instead. no cap, this one matters.
To see the usage:
% netaddr --help
__ __ __
____ ___ / /_____ _____/ /___/ /____
/ __ \/ _ \/ __/ __ `/ __ / __ / ___/
/ / / / __/ /_/ /_/ / /_/ / /_/ / /
/_/ /_/\___/\__/\__,_/\__,_/\__,_/_/
usage: netaddr [-h]
The netaddr CLI tool
options:
-h, --help show this help message and exit
Share and enjoy!
the banner? immaculate. "Share and enjoy!"? we love a friendly sign-off π«Ά
π Interactive shell π
Calling netaddr without any arguments will launch an interactive shell. literally just type netaddr and you're in.
The shell uses IPython <https://pypi.org/project/ipython/> if available, or the built-in Python REPL otherwise. The IPython REPL has more features and offers nicer experience overall β so like, if you have it, slay, and if not, it still works, bestie.
The shell comes with all parts of the netaddr API pre-imported so you can interact with it right away, with minimal friction β no imports, no setup, just vibes:
% 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]:
Changed in version 1.2.0: Made IPython an optional dependency. β¨
π Network information π
Run netaddr info <network> to display information about an IP network:
% 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
okay but the fact that you get the binary AND the hex AND the decimal in one shot? that's the whole subnet in one glow-up. π₯
π Standards and References π
The following references are applicable to the netaddr library. citations, but make it cute.
π RFCs π
The following RFCs have guided netaddr's feature set and capabilities.
IPv4
- RFC 791 - Internet Protocol β <http://www.ietf.org/rfc/rfc791>
- RFC 1918 - Address Allocation for Private Internets β <http://www.ietf.org/rfc/rfc1918>
- RFC 3330 - Special-Use IPv4 Addresses β <http://www.ietf.org/rfc/rfc3330>
- RFC 3927 - Dynamic Configuration of IPv4 Link-Local Addresses β <http://www.ietf.org/rfc/rfc3927>
Multicast (IPv4)
- RFC 2365 - Administratively Scoped IP Multicast β <http://www.ietf.org/rfc/rfc2365>
- RFC 3171 - IANA IPv4 Multicast Guidelines β <http://www.ietf.org/rfc/rfc3171>
- RFC 3927 - Dynamic Configuration of IPv4 Link-Local Addresses β <http://www.ietf.org/rfc/rfc3927>
IPv6
- RFC 3330 - Special-Use IPv4 Addresses β <http://www.ietf.org/rfc/rfc3330>
- RFC 4291 - IPv6 Addressing Architecture β <http://www.ietf.org/rfc/rfc4291>
- RFC 3306 - Unicast-Prefix-based IPv6 Multicast β <http://www.ietf.org/rfc/rfc3306>
- RFC 3956 - The RP Address in IPv6 Multicast Address β <http://www.ietf.org/rfc/rfc3956>
- RFC 3879 - Deprecating Site Local Addresses β <http://www.ietf.org/rfc/rfc3879>
- RFC 4193 - Unique Local IPv6 Unicast Addresses β <http://www.ietf.org/rfc/rfc4193>
- RFC 4941 - Privacy Extensions for Stateless Address β <http://www.ietf.org/rfc/rfc4941>
- RFC 1924 - A Compact Representation of IPv6 Addresses β <http://www.ietf.org/rfc/rfc1924>
Classless Inter-Domain Routing (CIDR)
- RFC 1338 - Supernetting: an Address Assignment and Aggregation Strategy β <http://www.ietf.org/rfc/rfc1338>
- RFC 4632 - Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan β <http://www.ietf.org/rfc/rfc4632>
ποΈ Data Sources ποΈ
Data from the following sources is exposed via the netaddr API.
Internet Assigned Numbers Authority (IANA)
- IANA Protocol Registry β <http://www.iana.org/protocols/>
- IPv4 Address Space β <http://www.iana.org/assignments/ipv4-address-space>
- IPv6 Address Space β <http://www.iana.org/assignments/ipv6-address-space>
- Multicast Registrations β <http://www.iana.org/assignments/multicast-addresses>
Institute of Electrical and Electronics Engineers (IEEE)
- IEEE Organisation Registry β <http://standards.ieee.org/regauth/oui/index.shtml>
- OUI (Organisationally Unique Identifier) Registrations β <http://standards.ieee.org/regauth/oui/oui.txt>
- IAB (Individual Address Block) Registrations β <http://standards.ieee.org/regauth/oui/iab.txt>
π HOW-TO GUIDES π
π How to release netaddr π
Here is how to go about releasing a new version of netaddr. deep breaths, bestie, we got this. π
- Make sure you have the necessary dependencies installed:
pip install --upgrade wheel twine
- Pull down the latest set of changes for the master branch.
The assumption is the master branch build is green and everything works correctly (we have a CI process in place). green build = good vibes only.
- Update the top-most section in the
CHANGELOG.rstwith details of all notable changes since the last release that aren't there already.
Set the release date to the current day. π
- Decide what the new version should be (depending on the changes that will be present in this release):
- Fixes β patch version bump
- New features β minor version bump
- Substantial or breaking changes β major version bump
- Update the version numbers throughout the source code. That includes changing the currently version number in
netaddr/__init__.pydocs/source/conf.py
and replacing all NEXT_NETADDR_VERSION instances with the new version (except for places like this file, of course). yeah, don't touch this one lol.
- Commit all changes.
- Build and publish the package:
make build-and-publish
- Tag the release and sync it to remote repo:
git tag -a x.y.z -m 'Release version x.y.z'
make push_tags
- Create a GitHub Release <https://github.com/netaddr/netaddr/releases/new> based on the tag you just pushed.
Put the new CHANGELOG.rst contents there and add the "Full changelog" link at the end (copy and adapt from the previous release).
π CHANGELOG π
NEXT_NETADDR_VERSION
Date: not released yet
Release: 1.3.0
Date: 2024-05-28
Added:
- Add partial address expansion in
IPNetworkvia theexpand_partialswitch, this enables opting into pre-1.1.0 behavior
Fixed:
- Fix running the test suite on musl systems
- Fix
IPAddressIPv6 parsing withZEROFILL(#netaddr.ZEROFILL) enabled - Fix handling of the
NOHOST(#netaddr.NOHOST) flag in theIPNetworkcopy constructor
Release: 1.2.1
Date: 2024-02-17
Fixed:
- Fix bad version 1.2.0 upload to PyPI β now yanked. No changes to the package. π
Release: 1.2.0
Date: 2024-02-17
Added:
- Add CLI tool subcommand to display Network information (
#cli-network-info).
Changed:
- Support running Interactive shell (
#interactive-shell) without IPython installed.
Fixed:
- Explicitly raise
TypeErrorif a non-string value is passed tovalid_ipv4()orvalid_ipv6().
Release: 1.1.0
Date: 2024-02-15
Added:
- Add the required Python version to the package metadata (GH #365 <https://github.com/netaddr/netaddr/issues/365>).
- Add
expand_partial_ipv4_address()to the public API.
Fixed:
- Fix
IPNetwork(...)inIPRange(...)false negatives (GH #157 <https://github.com/netaddr/netaddr/issues/157>). - Fix a few
IPNetworkslicing edge cases (GH #214 <https://github.com/netaddr/netaddr/issues/214>). - Fix support for partial IP addresses accidentally left in
IPNetworkin 1.0.0.
When I removed the implicit_prefix switch I missed the fact that there was some partial IPv4 address expansion triggered unconditionally.
If you need the old behavior use expand_partial_ipv4_address().
Related GH issue: #110 <https://github.com/netaddr/netaddr/issues/110>.
- Fixed an incorrect license classifier in the package metadata.
Release: 1.0.0
Date: 2024-02-10
Removed:
- Drop support for Python versions lower than 3.7.
- Remove the flag shorthands:
N,PandZ. UseNOHOST(#netaddr.NOHOST),INET_PTON(#netaddr.INET_PTON) andZEROFILL(#netaddr.ZEROFILL) instead. - Remove abbreviated CIDR format support in
IPNetwork(implicit_prefix=True), usecidr_abbrev_to_verbose()if you need this behavior. - Remove the
IPAddress.is_privatemethod.
There are more precise replacements for subset of the addresses that used to handled by is_private:
IPAddress.is_link_local()IPAddress.is_ipv4_private_use()IPAddress.is_ipv6_unique_local()IPAddress.is_global()
The following address blocks used to be handled by is_private have no dedicated convenience methods and you'll have to handle them manually or request a method addition:
100.64.0.0/10β Shared Address Space192.0.0.0/24β IETF Protocol Assignments (watch out β there are exceptions in there)198.18.0.0/15β Benchmarking239.0.0.0-239.255.255.255β240.0.0.0/4is Reserved,239.0.0.0/8β unclear
Changed:
- Stop accepting leading zeros when parsing IPv4 addresses in
INET_PTON(#netaddr.INET_PTON) mode (it's been allowed on some platforms).
If you need to allow and discard leading zeros use the ZEROFILL (#netaddr.ZEROFILL) flag.
This change will affect implicit conversions from str in all relevant contexts. If you need to control the IPv4 parsing mode construct IPAddress objects explicitly.
- Stop parsing IPv4 addresses permissively (
inet_aton()-like) by default. π
INET_PTON is the default mode now. Slay.
If you need to be permissive and parse using inet_aton() semantics, use the INET_ATON flag.
This change will affect implicit conversions from str in all relevant contexts. If you need to control the IPv4 parsing mode, construct IPAddress objects explicitly. No cap.
- Apply the two changes above to
valid_ipv4()as well. β - Update the address databases to the 2024-02-10 versions. π
Fixed:
- Return
Falseinstead of raisingAddrFormatErrorwhen an empty string is passed tovalid_ipv4()orvalid_ipv6(). π ββοΈ - Fix handling of dialect provided to
EUIduring copy-construction. π οΈ
Release: 0.10.1
Date: 2024-01-02
Fixed
- Get rid of some warnings. π§Ή
Deprecated
- Deprecate the flag shorthands:
N,PandZ. UseNOHOST,INET_PTONandZEROFILLinstead. π« - Deprecate importing objects from
netaddrsubpackages. Only importing things from the top-levelnetaddrnamespace is supported, everything else is considered private. This has already been the case but we can use a reminder. π - Deprecate permissive-by-default IPv4 parsing in
valid_ipv4(). Theinet_pton()semantics (with leading zeros always disallowed) will become the default. UseINET_ATONand/orZEROFILLflags if you need the legacy behavior. β οΈ
Release: 0.10.0
Date: 2023-12-31
Added
- Add an
INET_ATONflag to explicitly requestinet_aton()IPv4 parsing semantics fromIPAddress. β¨ - Add an
IPAddress.is_ipv4_private_use()convenience method. π‘ - Add an
IPAddress.is_global()convenience method to allow determining if an address is considered globally reachable. π - Add an
IPAddress.is_ipv6_unique_local()convenience method. π
Fixed
- Improve Python 3.13 compatibility, thank you John Eckersberg. π
Deprecated
- Deprecate Python 3.7 support. π
- Deprecate abbreviated CIDR format support in
IPNetwork(implicit_prefix=True). π¦ - Deprecate accepting leading zeros when parsing IPv4 addresses in
INET_PTONmode (it's been allowed on some platforms). If you need to allow and discard leading zeros use theZEROFILLflag. This change will affect implicit conversions fromstrin all relevant contexts. If you need to control the IPv4 parsing mode constructIPAddressobjects explicitly. β οΈ - Deprecate parsing IPv4 addresses permissively (
inet_aton()-like) by default.INET_PTONwill become the default mode. If you need to be permissive and parse usinginet_aton()semantics use theINET_ATONflag. This change will affect implicit conversions fromstrin all relevant contexts. If you need to control the IPv4 parsing mode constructIPAddressobjects explicitly. π¨ - Deprecate the
IPAddress.is_privatemethod. Migration instructions in the documentation. π
Other
- Raise an exception if invalid flags are passed to
IPAddress,IPNetworkorIPRange. π₯ - Improve the documentation substantially. π
- Update the DB files to the latest versions (2023-12-23). ποΈ
Release: 0.9.0
Date: 2023-09-18
Added
- Add hash capabilities to
OUI(#225, amitmi704). π
Fixed
- Backwards incompatible: Handle RFC 6164 IPv6 addresses (don't reserve first IP address in point-to-point subnets) (
$267, Damien Claisse). π¬ - Technically backwards incompatible: Fix for
is_loopbackbehaviour β considerIPNetwork('::1/128')to be loopback (#222, #223, niels). π - Include tutorials in source distributions (#215, Louis Sautier). π
- Fix a documentation typo (#242, Wouter). βοΈ
- Fix print syntax in the documentation to be Python 3 compatible (#221, FranΓ§ois Magimel). π¨οΈ
- Fix the Sphinx syntax in the documentation (#220, FranΓ§ois Magimel). π
Other
- Update the databases (#266, Jakub Stasiak). ποΈ
- Deprecate Python 3.6 (#263, Jakub Stasiak). π
- Eliminate unnecessary evals (#228, KOLANICH). π§Ή
Release: 0.8.0
Date: 3 Jul 2020
Changes since 0.7.20
- Fixed weak reference support in classes with
__slots__. π§· - Added
__bytes__toIPAddressfor intuitive usage, thanks to Michael Belousov. π’ - Added
format()function toEUI, thanks to Omer Anson. π¨ - Added
IPNetwork.netmaskproperty setter, thanks to Naveen Nathan. π οΈ - Added support for IABs in the
40:D8:55OUI, thanks to Brian Maissy. π·οΈ - Drastically optimized
spanning_cidr(), thanks to Brian Maissy. β‘ - Fixed "x.x.x.x/x" in
IPNetworktests, thanks to xpac1985. π§ͺ - Added support for passing iterables of
IPRangetoIPSetandcidr_merge(), based on a patch by Henry Stern. π
Specific bug fixes addressed in this release
- FIXED Issue 205: <https://github.com/netaddr/netaddr/issues/205>
- N log N complexity instead of linear. π
- FIXED Issue 171: <https://github.com/netaddr/netaddr/issues/171>
- Efficiently creating a large
IPSetfrom a list ofIPRanges? π€
- Efficiently creating a large
- FIXED Issue 161: <https://github.com/netaddr/netaddr/issues/161>
- Weak reference support. π§΅
Miscellanea
- The next release (0.9.0) will contain a backwards incompatible change in
IPNetwork's behaviour. It's connected to handling of RFC 6164 IPv6 addresses (/127and/128):IPNetwork.broadcastwill returnNonefor those and first addresses in the networks will no longer be excluded when iteratingIPNetworkandIPNetwork.iter_hosts(). See <https://github.com/netaddr/netaddr/pull/168> (or temporarily reverted commit2984c0a40a70in this repository) to see the actual patch. β οΈ
Release: 0.7.20
Date: 19 Jun 2020
Changes since 0.7.19
- Fixed returning from an iterator on Python 3.7+, by Sergey Kozlov. π
- Fixed Python 3.8
SyntaxWarningon usingis notwith a string literal, by Stefan Nordhausen. π - Fixed
DeprecationWarnings by using raw strings for escape characters used in regexes, by Sean McGinnis. π§Ή - Improved
IPGlobdocumentation, by obkmeta. π - Fixed exception creation in corner cases by explicitly passing error message params as tuples, by Matthias Urlichs. π οΈ
- Stopped manually replacing shebang of an included script. π
- Stopped using
__file__in all code that's expected to run in environments that don't support it (like PyOxidizer-produced binaries). π« - Updated all databases included in the package. ποΈ
Specific bug fixes addressed in this release
- FIXED Issue 182: <https://github.com/netaddr/netaddr/issues/182>
test_ip_splitter_remove_prefix_larger_than_input_rangefails with python 3.7. π
- FIXED Issue 206: <https://github.com/netaddr/netaddr/issues/206>
""is not" with a literal." SyntaxWarning. β οΈ
- FIXED Issue 198: <https://github.com/netaddr/netaddr/issues/198>
ouidatabases are outdated. π
- FIXED Issue 188: <https://github.com/netaddr/netaddr/issues/188>
- Avoid use of
__file__. π«
- Avoid use of
Miscellanea
- Python 2 versions older than 2.7 and Python 3 versions older than 3.5 should be considered unsupported. No incompatible code has been introduced to the best of our knowledge but there's no CI infrastructure in place to verify this and if there are any issues with those versions they won't be fixed. π«
- Consequently, Python 2.7 and 3.5 support should be considered deprecated as 2.7 has reached its end-of-life already and 3.5 will hit it soon. π
- A CI setup has been introduced which allows us to test on a variety of Python versions on all Mac, Linux and Windows. π₯οΈ
Release: 0.7.19
Date: 11 Jan 2017
Changes since 0.7.18
- added a new
SubnetSplitterclass for those looking to divide up subnets. Thanks alanwill and RyPeck and those on (Stack Overflow discussion). π§© - removed bundled
pytestdependency code for"python setup.py test". π§Ή setup.pynow usessetuptoolsonly (no moredistutils) andsetup_egg.pyremoved. π οΈ- cleaned up
INSTALLdocs so they accurately reflect current Python packaging. π - fixed broken parsing, generating and reading of IEEE index files when switching between Python 2.x and 3.x. π
Specific bug fixes addressed in this release
- FIXED Issue 133: <https://github.com/drkjam/netaddr/issues/133>
- Splitting a single network into multiple prefixed networks. βοΈ
- FIXED Issue 129: <https://github.com/drkjam/netaddr/issues/129>
- fix
IPAddress().netmask_bitsto return 0 for0.0.0.0and[::]addresses. π’
- fix
- FIXED Issue 117: <https://github.com/drkjam/netaddr/issues/117>
- (
python setup.py test) failing with python3 >= 3.5. π
- (
- FIXED Issue 137: <https://github.com/drkjam/netaddr/issues/137>
- API reference is broken on ReadTheDocs. π
- FIXED Issue 143: <https://github.com/drkjam/netaddr/issues/143>
- Please refresh the bundled IANA and IEEE databases. ποΈ
Miscellanea
- Goodbye to NYSE Euronext (good times), hello Intercontinental Exchange ... π
Release: 0.7.18
Date: 4 Sep 2015
Changes since 0.7.17
cidr_merge()algorithm is now O(n) and much faster. Thanks to Anand Buddhdev (aabdnn) and Stefan Nordhausen (snordhausen). β‘nmaptarget specification now fully supported including IPv4 CIDR prefixes and IPv6 addresses. π―
Specific bug fixes addressed in this release
- FIXED Issue 100: <https://github.com/drkjam/netaddr/issues/100>
nmap.py- CIDR targets. π―
- FIXED Issue 112: <https://github.com/drkjam/netaddr/issues/112>
- Observation: netaddr slower under pypy. π’
Release: 0.7.17
Date: 31 Aug 2015
Changes since 0.7.16
- Fixed a regression with
valid_macdue to shadow import in thenetaddrmodule. π οΈ
Specific bug fixes addressed in this release
- FIXED Issue 114: <https://github.com/drkjam/netaddr/issues/114>
netaddr.valid_mac('00-B0-D0-86-BB-F7')==Falsefor 0.7.16 butTruefor 0.7.15. π
Release: 0.7.16
Date: 30 Aug 2015
Changes since 0.7.15
- IPv4 networks with
/31and/32netmasks are now treated according to RFC 3021. Thanks to kalombos and braaen. π
Specific bug fixes addressed in this release
- FIXED Issue 109: <https://github.com/drkjam/netaddr/issues/109>
- Identify registry of global IPv6 unicast allocations. π
- FIXED Issue 108: <https://github.com/drkjam/netaddr/issues/108>
- One part of docs unclear? π€
- FIXED Issue 106: <https://github.com/drkjam/netaddr/issues/106>
Eui64Updated (pull request for Issue 105). π
- FIXED Issue 105: <https://github.com/drkjam/netaddr/issues/105>
- Support dialects for
EUI-64addresses. π
- Support dialects for
- FIXED Issue 102: <https://github.com/drkjam/netaddr/issues/102>
0.7.15tarball is missing tests.
FIXED Issue 96: https://github.com/drkjam/netaddr/issues/96
- Wrong hosts and broadcasts for
/31and/32networks.
π Release: 0.7.15
Date: 29 Jun 2015
Changes since 0.7.14
- Fix slowness in
IPSet.__contains__. Thanks to novas0x2a for noticing π - Normalize
IPNetworks when they are added to anIPSet⨠- Converted test suite to
py.testπ§ͺ
Specific bug fixes addressed in this release
FIXED Issue 98: https://github.com/drkjam/netaddr/issues/98
- Convert test suite to
py.test
FIXED Issue 94: https://github.com/drkjam/netaddr/issues/94
IPSet.__contains__is about 40 times slower than the equivalentIPRangeπ
FIXED Issue 95: https://github.com/drkjam/netaddr/issues/95
- Inconsistent Address Handling in
IPSetπ«
πΈ Release: 0.7.14
Date: 31st Mar 2015
Changes since 0.7.13
- Fix weird build breakage in
0.7.13(wrong Python path, incorrect OUI DB). π EUI,OUI, andIABobjects can now be compared with strings. You can do
my_mac = EUI("11:22:33:44:55:66") my_mac == "11:22:33:44:55:66"
and Python will return True on the == operator. β¨
- Implement the
!=operator forOUIandIABunder Python2. It was already working under Python3. π - 64 bit EUIs could only be created from strings with
-as a separator. Now,:and no separator are supported, which already worked for 48 bit EUIs. π¦
Specific bug fixes addressed in this release
FIXED Issue 80: https://github.com/drkjam/netaddr/pull/80
- Compare L2 addresses with their representations
FIXED Issue 81: https://github.com/drkjam/netaddr/issues/81
- OUI database tests fail in
0.7.13
FIXED Issue 84: https://github.com/drkjam/netaddr/issues/84
- Incorrect python executable path in
netaddr-0.7.13-py2.py3-none-any.whl
FIXED Issue 87: https://github.com/drkjam/netaddr/pull/87
- Handle eui64 addresses with colon as a delimiter and without delimiter.
π Release: 0.7.13
Date: 31st Dec 2014
Changes since 0.7.12
IPAddressobjects can now be added to/subtracted from each other ββ
Specific bug fixes addressed in this release
FIXED Issue 73: https://github.com/drkjam/netaddr/issues/73
- Adding IP Addresses
FIXED Issue 74: https://github.com/drkjam/netaddr/issues/74
- compute static global ipv6 addr from the net prefix and mac address
FIXED Issue 75: https://github.com/drkjam/netaddr/issues/75
- add classifiers for python 3.3 and 3.4 support
π Release: 0.7.12
Date: 6th Jul 2014
Changes since 0.7.11
- Added method
IPSet.iter_ipranges(). π bool(IPSet())works now for largeIPSets, e.g.IPSet(['2405:8100::/32']). π«ΆIPNetwork.iter_hostsnow skips the subnet-router anycast address for IPv6.- Removed function
fbsocket.inet_atonbecause it is unused and unnecessary ποΈ
Specific bug fixes addressed in this release
FIXED Issue 69: https://github.com/drkjam/netaddr/issues/69
- Add
__nonzero__method toIPSet
FIXED Pull Request 68: https://github.com/drkjam/netaddr/pull/68
- Fixed a bug related to allowing
::0duringiter_hostsfor v6
FIXED Issue 67: https://github.com/drkjam/netaddr/issues/67
- Remove function
fbsocket.inet_aton
FIXED Pull Request 66: https://github.com/drkjam/netaddr/pull/66
- Added Function to create list of
IPRangefor non-contiguousIPSet
π₯ Release: 0.7.11
Date: 19th Mar 2014
Changes since 0.7.10
- Performance of
IPSetincreased dramatically, implemented by Stefan Nordhausen and Martijn van Oosterhout. As a side effect,IPSet(IPNetwork("10.0.0.0/8"))is now as fast as you'd expect. β‘ - Various performance improvements all over the place.
netaddris now hosted on PyPI and can be installed viapip. π¦- Doing
"10.0.0.42" in IPNetwork("10.0.0.0/24")works now. β IPSethas two new methods:iscontiguous()andiprange(), thanks to Louis des Landes. π- Re-added the
IPAddress.netmask_bits()method that was accidentally removed. - Networks
128.0.0.0/16,191.255.0.0/16, and223.255.255.0/24are not marked as reserved IPv4 addresses any more. Thanks to marnickv for pointing that out. π«‘ - Various bug fixes contributed by Wilfred Hughes, 2*yo and Adam Goodman. π
Specific bug fixes addressed in this release
FIXED Issue 58: https://github.com/drkjam/netaddr/issues/58
foo.bardoesn't throwAddrFormatError
FIXED Issue 57: https://github.com/drkjam/netaddr/issues/57
netaddrpackages not hosted on PyPI
FIXED Issue 56: https://github.com/drkjam/netaddr/issues/56
- Fix comparison with large
IPSet()
FIXED Issue 55: https://github.com/drkjam/netaddr/pull/55
- Fix
smallest_matching_cidrandall_matching_cidrs
FIXED Issue 53: https://github.com/drkjam/netaddr/issues/53
- Exclude
128.0.0.0/16and possibly others from reserved range set?
FIXED Issue 51: https://github.com/drkjam/netaddr/issues/51
- Encoding errors in
netaddr/eui/oui.txt
FIXED Issue 46: https://github.com/drkjam/netaddr/issues/46
len(IPSet())fails on python3
FIXED Issue 43: https://github.com/drkjam/netaddr/issues/43
- Method to check if
IPSetis contiguous
FIXED Issue 38: https://github.com/drkjam/netaddr/issues/38
netmask_bitsis missing from theIPAddress
FIXED Issue 37: https://github.com/drkjam/netaddr/issues/37
- Test failures with Python 3.3
π¦ Release: 0.7.10
Date: 6th Sep 2012
Changes since 0.7.9
- A bunch of Python 3.x bug fixes. Thanks Arfrever. π
- Extended nmap support to cover full target specification. πΊοΈ
Specific bug fixes addressed in this release
FIXED Issue 36 - https://github.com/drkjam/netaddr/issues/36
- ResourceWarnings with Python >=3.2
FIXED Issue 35 - https://github.com/drkjam/netaddr/issues/35
netaddr-0.7.9: Test failure with Python 3
FIXED Issue 34 - https://github.com/drkjam/netaddr/issues/34
netaddr.ip.iana.SaxRecordParser.endElement()incompatible with Python 3.1
FIXED Issue 33 - https://github.com/drkjam/netaddr/issues/33
netaddrscript not installed with Python 3
FIXED Issue 23 - https://github.com/drkjam/netaddr/issues/23
valid_nmap_range()does not validate nmap format case.
FIXED Issue 22 - https://github.com/drkjam/netaddr/issues/22
all_matching_cidrs: documentation incorrect
π Release: 0.7.9
Date: 28th Aug 2012
Changes since 0.7.8
- Re-release to fix build removing Sphinx dependency. π
β Release: 0.7.8
Date: 28th Aug 2012
Changes since 0.7.7
- New SAX parser for IANA data source files (contributed by Andrew Stromnov) π
- Fixed pickling failures with
EUI,OUIandIABclasses. π₯
Specific bug fixes addressed in this release
FIXED Issue 31 - https://github.com/drkjam/netaddr/issues/31
- Exclude
'39.0.0.0/8'network from reserved set. Thanks Andrew Stromnov
FIXED Issue 28 - https://github.com/drkjam/netaddr/issues/28
- Fix algorithm in
ipv6_link_localto fully conform torfc4291. Thanks Philipp Wollermann
FIXED Issue 25 - https://github.com/drkjam/netaddr/issues/25
install_requiresis too aggressive? Thanks Adam Lindsay and commenters.
FIXED Issue 21 - https://github.com/drkjam/netaddr/issues/21
deepcopyforEUIfails. Thanks Ryan Nowakowski.
π
Release: 0.7.7
Date: 30th May 2012
Changes since 0.7.6
- Comprehensive documentation update! It's only taken 4 years to get around to using Sphinx and I can confirm it is TOTALLY AWESOME! π€β¨
- Various bug fixes
- Refreshed IEEE OUI and IAB data π
Specific bug fixes addressed in this release
FIXED Issue 24 - https://github.com/drkjam/netaddr/issues/24
- Fixed
TypeErrorwhen comparingBaseIPinstance with non-BaseIPobjects. Thanks pvaret
FIXED Issue 17 - https://github.com/drkjam/netaddr/issues/17
- For large ipv6 networks the
.subnet()method fails. Thanks daveyss
FIXED Issue 20 - https://github.com/drkjam/netaddr/issues/20
- Test failure with Python 3. Thanks Arfrever
π Release: 0.7.6
Date: 13th Sep 2011
Changes since 0.7.5
- A bug fix point release π
- Refreshed 3rd party data caches
- Tested against Python 3.2.x and PyPy 1.6.x
- Fixed unit tests under for Mac OSX π
Specific bug fixes addressed in this release
FIXED Issue 15 - https://github.com/drkjam/netaddr/issues/15
- Incorrect and invalid glob produced when last octet is not
*
FIXED Issue 13 - https://github.com/drkjam/netaddr/issues/13
- Added support for IPython 0.11 API changes. Thanks juliantaylor
FIXED Issue 11 - https://github.com/drkjam/netaddr/issues/11
- Calling
valid_globon cidr raisesValueError. Thanks radicand
FIXED Issue 7 - https://github.com/drkjam/netaddr/issues/7
- Unpickling Bug in
IPSet. Thanks LuizOz and labeneator
FIXED Issue 2 - https://github.com/drkjam/netaddr/issues/2
UnboundLocalErrorraised inIPNetworkconstructor. Thanks keesbos
Miscellanea π₯€
- Has a famous soft drink company started making it own NICs? π
π§ Release: 0.7.5
Date: 5th Oct 2010
Changes since 0.7.4
- Python 3.x is now fully supported. The paint is still drying on this so please help with testing and raise bug tickets when you find any issues! New Issue Tracker -
https://github.com/drkjam/netaddr/issuesπβ¨ - Moved code hosting to github. History ported thanks to svn2git. - (β
https://github.com/nirvdrum/svn2git) - All
netaddrobjects now use approx. 65% less memory due to the use of__slots__in classes throughout the codebase. Thanks to Stefan Nordhausen and his Python guru for this suggestion! πͺΆ - Applied many optimisations and speedups throughout the codebase. β‘
- Fixed the behaviour of the
IPNetworkconstructor so it now behaves in a much more sensible and expected way (i.e. no longer usesinet_atonsemantics which is just plain odd for network addresses). π§ - One minor change to behaviour in this version is that the
.valueproperty onIPAddressandIPNetworkobjects no longer support assignment using a string IP address. Only integer value assignments are now valid. The impact of this change should be minimal for the majority of users.
Heads up bestie β that .value thing is a real behaviour change, so if you were assigning strings to it, that's done now. Integers only, periodt. β οΈ
Specific bug fixes addressed in this release
FIXED Issue 49 - http://code.google.com/p/netaddr/issues/detail?id=49
- Incorrect IP range recognition on IPs with leading zeros
FIXED Issue 50 - http://code.google.com/p/netaddr/issues/detail?id=50
- CIDR block parsing
FIXED Issue 52 β http://code.google.com/p/netaddr/issues/detail?id=52
- ipv6 cidr matches incorrectly match ipv4 [sic]
FIXED Issue 53 β http://code.google.com/p/netaddr/issues/detail?id=53
- Error in online documentation
FIXED Issue 54 β http://code.google.com/p/netaddr/issues/detail?id=54
- IP recognition failure
FIXED Issue 55 β http://code.google.com/p/netaddr/issues/detail?id=55
- Support for Python 3.x
FIXED Issue 56 β http://code.google.com/p/netaddr/issues/detail?id=56
- checking IPAddress in IPNetwork
FIXED Issue 57 β http://code.google.com/p/netaddr/issues/detail?id=57
- netaddr objects can't pickle
FIXED Issue 58 β http://code.google.com/p/netaddr/issues/detail?id=58
- IPSet operations should accept the same arguments as IPAddress
FIXED Issue 59 β http://code.google.com/p/netaddr/issues/detail?id=59
- netaddr fails to load when imported by a PowerDNS coprocess
Miscellanea <butterfly emoji vibes>
- Welcome back to standards.ieee.org which seems to have been down for weeks! (we missed u bestie π)
- Goodbye Sun Microsystems + Merrill Lynch, hello Oracle + Bank of America ... (corporate lore, honestly)
π Release: 0.7.4 π
Date: 2nd Dec 2009
Changes since 0.7.3
- Applied speed patches by S. Nordhausen (zoom zoom β¨)
- Fixed an inconsistency between EUI and IPAddress interfaces. Made
EUI.packedandEUI.binproperties (previously methods) and added awords()property. (glow-up fr)
πΈ Release: 0.7.3 πΈ
Date: 14th Sep 2009
Changes since 0.7.2
- Added
__add__,__radd__,__sub__,__rsub__operators to theIPAddressclass. (math era π ) - Added support for validation and iteration of simple nmap style IPv4 ranges (raised in Issue 46).
- Removed some unused constants from fallback socket module.
Specific bug fixes addressed in this release
FIXED Issue 44 β http://code.google.com/p/netaddr/issues/detail?id=44
- int/long type error
FIXED Issue 46 β http://code.google.com/p/netaddr/issues/detail?id=46
- Question about IPv4 ranges
FIXED Issue 47 β http://code.google.com/p/netaddr/issues/detail?id=47
- IPNetwork cannot be evaluated as a boolean when it has a large size
π Release: 0.7.2 π
Date: 20th Aug 2009
Changes since 0.7.1
FIXED a boundary problem with the iter_iprange() generator function and all associated calls to it throughout the codebase, including unit test coverage and adjustments. (edge cases found quaking π«£)
- Replaced regular expressions in
cidr_merge()with pre-compiled equivalents for a small speed boost. β‘ - Adjustments to README raised by John Eckersberg.
Specific bug fixes addressed in this release
FIXED Issue 43 β http://code.google.com/p/netaddr/issues/detail?id=43
IPNetwork('0.0.0.0/0')not usable in for loop
π¦ Release: 0.7.1 π¦
Date: 14th Aug 2009
Changes since 0.7
- Renamed the netaddr shell script from
'nash'to plain'netaddr'. This is to avoid a potentially nasty clash with an important Linux tool with the same name. (imagine the chaos π¬)
Thanks to John Eckersberg for spotting this one early!
- Updated IANA and IEEE data files with latest versions.
Specific bug fixes addressed in this release
FIXED Issue 42 β http://code.google.com/p/netaddr/issues/detail?id=42
- Bug in
cidr_merge()function when passed the CIDRs0.0.0.0/0and/or::/0
β Release: 0.7 β
Date: 11th Aug 2009
Changes since 0.6.x
Please Note β This release represents a major overhaul of netaddr. It breaks backward compatibility with previous releases. See the API documentation for full details of what is available. (bestie. read this. it WILL break ur code π)
Some highlights of what has changed :-
- Internal module hierarchy has been completely overhauled and redesigned. This fixes up a lot of inconsistencies and problems with interdependent imports. All public classes, objects, functions and constants are still published via the main
netaddrmodule namespace as in previous releases. - No more
AT_*andST_*'constants'. - The
Addrbase class is gone. This removes the link between EUI and IP functionality so the library is can now easily be split into distinct units without many interdependencies between layer 2 and layer 3 functionality. (we love decoupling β¨) - The use of custom descriptor classes has been completely discontinued.
- Strategy classes and singleton objects have been replaced with a group of strategy modules in their own
netaddr.strategynamespace. Each IP or EUI address object now holds a reference to a module rather than a singleton object. - Many operations that were previously static class methods are now presented as functions in the relevant modules. See the API documentation for details.
- The
IPandCIDRclasses have been replaced with two new classes calledIPAddressandIPNetworkrespectively. This name change is important as theIPpart of netaddr has been completed redesigned. The notion of an individual IP address and an IP network or subnet has been made more obvious.IPAddressobjects are now true scalars and do not evaluate in a list or tuple context. They also do not support any notion of a netmask or CIDR prefix; this is the primary function of anIPNetworkobject. (scalar rights!! π«Ά) - Arbitrary IP ranges and are still supported but a lot of their functionality has also been exposed via handy functions.
- IP globbing routines (previous known as Wildcards) have been moved into their own submodule.
- Added a new
IPSetclass which fully emulates mutable Python sets. This replaces a lot of half-baked experimental classes found in 0.5.x and 0.6.x such asIPRangeSetandCIDRGroup. See documentation for details. (the glow-up of the century π) - All methods and properties that previously used or supported the
'fmt'formatting property no longer do so. In all cases, objects are now returned to correctly support pass through calls without side effects. It is up to the user to extract data in the right format from the objectsIPAddressobjects returned as required. - Unit tests have been completed re-written to support docstring style tests bundled into test suites. These are handy as they double up as documentation being combined with wiki syntax. Implemented code coverage checking using coverage 3.x.
nash- a nascent shell like tool for the netaddr library (requires IPython).- Support for RFC 1924 added ;-) (the winky face is doing so much work here)
Specific bug fixes addressed in this release
FIXED Issue 13 β http://code.google.com/p/netaddr/issues/detail?id=13
- Searching for a match in a list of CIDR objects
FIXED Issue 26 β http://code.google.com/p/netaddr/issues/detail?id=26
- Refactor out use of
isinstance()
FIXED Issue 28 β http://code.google.com/p/netaddr/issues/detail?id=28
- Add support for network block operations
FIXED Issue 34 β http://code.google.com/p/netaddr/issues/detail?id=34
- Addition issue?
π Release: 0.6.4 π
Date: 11th Aug 2009
Specific bug fixes addressed in this release
FIXED Issue 40 β http://code.google.com/p/netaddr/issues/detail?id=40
- Building RPM with
"python setup.py bdist_rpm"fails, multiple errors
π§ Release: 0.6.3 π§
Date: 23rd Jun 2009
Changes since 0.6.2
- Fixed line endings in a number of new files created under Windows.
- Tweaked the ordering of values in tuple passed into the
hash()function in the__hash__method of theIPandIPRangeclasses to make it the same as the values used for comparisons implemented in the__eq__method (Python best practice). (consistency slay π ) - Added a number of unit tests to improve code coverage.
Specific bug fixes addressed in this release
FIXED Issue 33 β http://code.google.com/p/netaddr/issues/detail?id=33
- CIDR subtraction is broken for out-of-range CIDR objects
FIXED Issue 35 β http://code.google.com/p/netaddr/issues/detail?id=35
- install error (on Python interpreters where
socket.has_ipv6isFalse)
FIXED Issue 36 β http://code.google.com/p/netaddr/issues/detail?id=36
netaddr.CIDRfails to parse default route CIDR
FIXED Issue 37 β http://code.google.com/p/netaddr/issues/detail?id=37
- Bug in bitwise AND operator for IP addresses
FIXED Issue 38 β http://code.google.com/p/netaddr/issues/detail?id=38
- Feature request:
Addr.__nonzero__
FIXED Issue 39 β http://code.google.com/p/netaddr/issues/detail?id=39
CIDR.abbrev_to_verbose()not applying implicit classful netmask rules consistently
π Release: 0.6.2 π
Date: 13th Apr 2009
Changes since 0.6.1
- Refreshed IEEE and IANA data files with latest revisions from their respective URLs.
- IANA IPv4 Address Space Registry (last updated 2009-03-11)
- Internet Multicast Addresses (last updated 2009-03-17)
- IEEE OUI and IAB files (last updated 2009-04-13)
- Added
get_latest_files()functions to both thenetaddr.euiandnetaddr.ipmodules to assist in automating release builds. (automation?? we love her βοΈ)
Specific bug fixes addressed in this release
FIXED Issue 32 β http://code.google.com/p/netaddr/issues/detail?id=32
Addr.__ne__returns wrong answer
π Release: 0.6.1 π
Date: 6th Apr 2009
Changes since 0.6
- Added
COPYRIGHTfile with details and attribution for all 3rd party files bundled with netaddr. - Minimum Python version required is now 2.4.x changed from 2.3.x. (rip 2.3, u had a good run π«‘)
- Python 2.3 compatibility code in many sections of code have been removed.
- the
@propertyand@staticmethoddecorators are now used throughout the code along with thereversed()andsorted()builtin iterators. - A specific version check has also been added that will raise
RuntimeErrorexceptions if you run netaddr on a Python interpreter version < 2.4.x.
- Integer addresses passed to the
IP()andEUI()constructors no longer require a mandatory second address type (AT_*) argument in most cases. This is now only really required to disambiguate between IPv4/IPv6 addresses with the same numerical value. The same behaviour applies to EUI-48/EUI-64 identifiers. A small speed boost is achieved if the 2nd address type argument is explicitly provided. - IPv6 addresses returned by
EUI.ipv6_link_local()now always have a subnet prefix of/64. - Default sort order of aggregate classes (
IPRange,CIDRandWildcard) has been changed (again). They now sort initially by first address and then by network block size from largest to smallest which feels more natural. (it DOES feel more natural ngl) - Fixed a bug in the
CIDR.abbrev_to_verbose()static method where IPv4 addresses with 4 octets (i.e. non-partial addresses) were being assigned subnet prefixes using abbreviated rules. All complete IPv4 addresses should always get a/32prefix where it is not explicitly provided. (/32 or it didn't happen β¨) expand_abbrevβ okay so abbreviated address expansion in the CIDR constructor is now optional, bestie, and itβs controlled by a new boolean argument calledexpand_abbrev. β¨CIDR.summarize()β a whole new static method just dropped, and itβs iconic: it transforms lists of IP addresses and CIDRs into their most compact forms. Great for trimming down large ad hoc address lists! πprevious()andnext()β added to the CIDR classes, and they return the CIDR subnets either side of a given CIDR that are of the same size. For the CIDR192.0.2.0/24,previouswill return192.0.1.0/24andnextwill return192.0.3.0/24. Also accepts an optional step size (default is1). πsupernet()β added to the CIDR class, and it returns a generator of all the subnets that contain the current CIDR found by decrementing theprefixlenvalue for each step until it reaches zero. π- fallback code vibes β changed the way the fallback code works when the
socketmodule is missing important constants and functions. lowkey important. - uppercase options removed β the uppercase options are gone from the Strategy constructors and internals, because this behaviour can be easily replicated using the
word_fmtoption instead and requires less code (word_fmt='%X'). periodt.
π Specific bug fixes addressed in this release π
FIXED Issue 23 - <http://code.google.com/p/netaddr/issues/detail?id=23>- Improve IPv6 IPv4 mapped/compatible address formatting
FIXED Issue 24 - <http://code.google.com/p/netaddr/issues/detail?id=24>- bug in
CIDR.subnet()when using thefmtargument
- bug in
FIXED Issue 29 - <http://code.google.com/p/netaddr/issues/detail?id=29>CIDR.subnetmethod'scountargument isn't working as documented
FIXED Issue 30 - <http://code.google.com/p/netaddr/issues/detail?id=30>- not compatible with Python 2.3
FIXED Issue 31 - <http://code.google.com/p/netaddr/issues/detail?id=31>- byte order in documentation confusing or wrong
π Release: 0.6 π
Date: 20th Jan 2009
π Changes since 0.5.x π
- Namespace changes β 3 new sub namespaces have been added :-
netaddr.euiβ Currently contains IEEE OUI and IAB classes and lookup code.netaddr.ipβ Currently contains IANA IPv4, IPv6 and IPv4 multicast lookup code.netaddr.coreβ Currently contains only a couple of classes that are shared between code innetaddr.euiandnetaddr.ip.
Please Note: This change is part of a two stage internal restructuring of netaddr. In future releases, layer-2 MAC/EUI functionality will be separated from and layer-3 IP, CIDR and Wildcard functionality. All shared code will be moved to netaddr.core. When the migration is complete (expected in 0.7) the netaddr.address and netaddr.strategy namespaces will be removed. Please endeavour to access everything you need via the top-level netaddr namespace from this release onwards. See netaddr.__all__ for details of constants, objects, classes and functions intended for the public interface.
- Addition of IEEE and IANA informational lookups
- the
IP()andEUI()classes now have an additionalinfo()method through which contextual information about your addresses can be accessed. This data is published by IANA and the IEEE respectively and sourced directly from text files bundled with netaddr that are available for download publicly online. Details are available in the docstring of the relevant parsing classes. Subsequent netaddr releases will endeavour to keep up-to-date with any updates to these files. - the
EUI()class has been updated with the addition of theOUI()andIAB()classes. They provide object based access to returned via theEUI.info()method. Please see API docs included with netaddr for details. - added new
NotRegisteredErrorexception that is raised when an EUI doesn't match any currently registration entries in the IEEE registry files. π
- the
Addr()class removed from the public interface- This class is only ever meant to be used internally and its usage may soon be deprecated in favour converting it into an abstract base class in future releases.
- Deletion of
AddrRange()class- replaced with the more specific
IPRange()class.AddrRange()wasn't very useful in practice. Too much time has been spent explaining its theoretical merits over its actual practicality for every day use.
- replaced with the more specific
- Addition of new
IPRange()class- the new base class for
CIDR()andWildcard(). - a 'killer feature' of this new class are the new methods
iprange(),cidrs()andwildcard()which allow you to use and switch between all 3 formats easily.IPRange('x', 'y').cidrs()is particularly useful returning all the intervening CIDRs between 2 arbitrary IP addresses. IPRange()is a great place to expose several new methods available to sub classes. They areissupernet(),issubnet(),adjacent()andoverlaps().- previous method called
data_flavour()has been renamed (again) to a more suitableformat().
- the new base class for
IP()class updatesis_netmask()andis_hostmask()methods have been optimised and are now both approximately 4 times faster than previously! π₯- added
wildcard()andiprange()methods that return pre-initialised objects of those classes based on the current netmask / subnet prefix. - copy constructor methods
ipv4()andipv6()now preserve the value of theprefixlenproperty now also support IPv6 options for returning IPv4-mapped or IPv4-compatible IPv6 addresses. - added new methods
is_loopback(),is_private(),is_link_local(),is_ipv4_mapped()andis_ipv4_compat()which are all self explanatory. - added a
bin()method which provides an IP address in the same format as the standard Pythonbin()builtin type ('0bxxx') now available in Python 2.6.x and higher. - added a
packed()method which provides an IP address in packed binary string format, suitable for passing directly to Python socket calls.
nrange()generator function updates- by default this now returns
IP()objects instead ofAddr()objects.
- by default this now returns
CIDR()class updates- the
'strict_bitmask'option in the CIDR class constructor has been had a name change and is now just'strict'(less typing). - support for Cisco ACL-style (hostmask) prefixes. Also available to the
IP()class. They are converted to their netmask equivalents before being applied to the base address. - added a new
subnet()generator method that returns iterators to subnet CIDRs found within the current CIDR object's boundaries e.g. a/24CIDR can provide address with subnet prefixes between a/25and/32. - added a new
span()method which takes a list of IP, IPRange, CIDR and/or Wildcards returning a single CIDR that 'spans' the lowest and highest boundary addresses. An important property of this class is that only a single CIDR is returned and that it (potentially) overlaps the start and end addresses. The most important aspect of this method is that it identifies the left-most set of bits that are common to all supplied addresses. It is the plumbing that makes a lot of other features function correctly. - although IPv6 doesn't support the concept of a broadcast address, after some pondering I've decided to add
network()andbroadcast()methods to the CIDR class. It is an interface quirk that users expect so it has been added for ease of use. - the methods
network(),broadcast(),hostmask()andnetmask()have been wrapped inproperty()builtin calls to make them appear as read-only properties.
- the
- Many more MAC and IPv4 string address representation are now supported
- Improvements to both
EUIandIPclasses. They now accept many more valid address formats than previously. Thanks for all the bugs tickets raised. π
- Improvements to both
__repr__()method behaviour change- Using
repr()now assume that you have performed afrom netaddr import *before you execute them. They no longer specify the originating namespace of objects which is a bit unnecessary and a lot to read on-screen. They will also be moving around within the namespace shortly anyway so its best not to think of them as being anywhere other than directly below netaddr itself.
- Using
'klass'property renamed to'fmt'(format)- now referred to as the
'format callable'property. An unfortunately but necessary change.'klass'was a bad initial name choice as it most often doesn't even reference a class object also supporting references to Python types, builtin functions and user defined callables.
- now referred to as the
- Complete re-work and consolidation of unit tests.
- now over 100 tests covering all aspects of the API and library functionality.
- Moved all tests into a single file. Lots of additional tests have been added along with interface checks to ensure netaddr's always presents a predictable set of properties and methods across releases.
- Nascent support for Python eggs and setuptools.
- Help is need to test this as it is not something I use personally. π
π Specific bug fixes addressed in this release π
- Finally fixed the IPv6 string address compression algorithm so that it is now compliant with the socket modules
inet_ntop()andinet_pton()calls. (not available on all platforms).
π§ͺ Experimental Features π§ͺ
- added bitwise operators to the
IPclass- does what it says on the tin. Does not affect the value of the IP object itself but rather, returns a new IP after the operation has been applied.
IPRangeSet()class added (EXPERIMENTAL).- the intention with this class is to allows you to create collections of unique
IP(),IPRange(),CIDR()andWildcard()objects. It provides iteration over IPs in the collection as well as several membership based operations such asany_match()all_matches(),min_match()andmax_match(). - lots more work to do here. Please raise bugs and feature requests against this as you find them. Improvements to this are coming in 0.7.
- the intention with this class is to allows you to create collections of unique
πΈ Release: 0.5.2 πΈ
Date: 29th Sep 2008
π Specific bug fixes addressed in this release π
- Fixed Issue 15 in bug tracker. Bad validation and conversion of IPv4 mapped IPv6 address values in
IPv6Strategyclass. Covered with unit test cases. - Updated
PrefixLenDescriptor()class so that modifications to the propertyCIDR.prefixlenalso updateCIDR.firstandCIDR.lastkeeping them in sync. Covered by unit test cases. IP.hostname()method returnsNonewhen DNS lookup fails.
π Release: 0.5.1 π
Date: 23rd Sep 2008
π Specific bug fixes addressed in this release
- The
CIDRconstructor was straight-up throwing aTypeErrorfor valid unicode string addresses that worked fine in previous releases. Bestie, it's fixed now, and it's covered with a unit test case so it can't sneak back in. β¨ - The methods
CIDR.netmask()andCIDR.hostmask()had actual code errors in them that were making them fail. Problem fixed, and yes β covered with a unit test case too. π
π¦ Release: 0.5
Date: 19th Sep 2008
Changes since 0.4.x
General β okay so this is the big one, grab a snack π
- Access to all the important object attributes in all
netaddrclasses now happens via custom Python descriptor protocol classes. This massively simplified the internal class logic and made external attribute changes way safer and less error prone. It also made aggregate classes such asCIDRandWildcardeffectively read-write rather than read-only, which they were up until this release. glow-up fr π - Amended the way sort order is calculated for
AddrandAddrRange(sub)class instances so that the address type gets taken into account as well as the numerical value of the address or address range. The ascending sort order is IPv4, IPv6, EUI-48 and EUI-64. Sequences ofAddrRange(sub)class instances now sort correctly! π - Comparisons between instances of
AddrandAddrRange(sub)classes now returnFalserather than raising anAttributeError. no more random jump-scares π - Added checks and workaround code for Python runtime environments that suffer from the infamous socket module
inet_aton('255.255.255.255')bug. This was discovered recently in Python 2.4.x on PowerPC under MacOS X. The fix also applies in cases where the socket module is not available (e.g. on Google App Engine). π₯ - All general
Exceptionraising in the strategy module has now been replaced with more specific exceptions, mainlyValueError(these were unintentionally missed out of the 0.4 release). π - Implemented
__hash__()operations for theAddrandAddrStrategyclasses. This means you can use IP, CIDR and Wildcard objects as keys in dictionaries and as elements in sets. Please note β this is currently an experimental feature which may change in future releases. β - Added
__ne__()operation toAddrandAddrRangeclasses. - Obeying the 'Law of Demeter', the address type of
AddrandAddrRange(sub)class instances can be accessed using the property directly:
obj.addr_type # 0.5 onwards
rather than having to go via the strategy object:
obj.strategy.addr_type # 0.4 and earlier
- Renamed the
AT_DESCRlookup dictionary toAT_NAMES. Also removed invalid and duplicated imports from all modules. tidy queen π§
Addr class changes
- Removed the
setvalue()method from theAddrclass, and replaced all uses of__setattr__()with custom descriptors throughout.
IP class changes
- Removed the ambiguity with
masklenandprefixlenattributes in theIPclass.prefixlennow denotes the number of bits that define the netmask for an IP address. The new methodnetmask_bits()returns the number of non-zero bits in an IP object if theis_netmask()method returnsTrue. Aprefixlenvalue other than/32for an address whereis_netmask()returnsTrueis invalid and will raise aValueErrorexception. β οΈ - Removed the
family()method from theIPclass. It duplicates information now provided by theprefixlenproperty. IPclass has several new methods.is_multicast()andis_unicast()quickly tell you what category of IP address you have, andipv4()andipv6()act as IPv4 <-> IPv6 conversions or copy constructors depending on context. love that for us π«Ά- Reverse DNS lookup entries now contain a trailing, top-level period (
.) character appended to them. - Added the
hostname()method toIPinstances which performs a reverse DNS - The
IPclass__str__()method now omits the subnet prefix, which is now implicit for IPv4 addresses that are/32and IPv6 addresses that are/128. Subnet prefix is maintained in the return value for all other values.
AddrRange class changes
- The
AddrRangeclass no longer stores instances ofAddr(sub)classes for the first and last address in the range. The instance variablesself.start_addrandself.stop_addrhave been renamed toself.firstandself.last, and the methodsobj.first()andobj.last()have been removed.
Instead, self.first and self.last contain integer values and a reference to a strategy object is stored. Doing this is a lot more useful and cleaner for implementing internal logic.
To get Addr (sub)class objects (or strings, hex etc when manipulating the klass property) use the index values obj[0] and obj[-1] as a substitute for obj.first() and obj.last() respectively.
AddrRange(sub)class instances now define the increment,__iadd__(), and decrement,__isub__(), operators. This allows you to 'slide' CIDRs and Wildcards upwards and downwards based on their block sizes. π sliding, iconic- The
_retval()method has now been renameddata_flavour()β yes, the UK spelling ;-) You shouldn't really care much about this as it's mostly for internal use. I gave it a decent name as I didn't see any real need to hide the functionality if users wanted it.
CIDR class changes
- The strictness of the
CIDRclass constructor in relation to non-zero bits once the prefix bitmask has been applied can be disabled using the optional argumentstrict_bitmask=False. It isTrue(strictness enabled) by default. - Fixed a bug in abbreviated CIDR conversion. Subnet prefix for multicast address
224.0.0.0is now/4instead of/8. - The
CIDRclass now supports subtraction between two CIDR objects, returning a list of the remainder. Please note that the bigger of the two CIDR objects must be on the left hand side of the expression, otherwise an empty list is returned. Sorry, you are not allowed to create negative CIDRs ;-) π - The function
abbrev_to_cidr()has been renamed to and turned into the static methodCIDR.abbrev_to_verbose(). No major changes to the logic have been made.
Wildcard class changes
- The
Wildcardclass now defines a static methodWildcard.is_valid()that allows you to perform validity tests on wildcard strings without fully instantiating aWildcardobject. efficiency slay β¨
π Release: 0.4
Date: 7th Aug 2008
Changes since 0.3.x
- All general
Exceptionraising has been replaced with more specific exceptions such asTypeErrorandValueError, plus the addition of two custom exception classes,AddrFormatErrorandAddrConversionError. π - The
IPclass now accepts a subnet prefix. It is NOT strict about non-zero bits to the right of the implied subnet mask, unlike theCIDRclass (see below). - The
CIDRclass is now completely strict about non-zero bits to the right of the implied subnet netmask and raises aValueErrorif they exist, with a handy hint as to the correct CIDR to be used based on the supplied subnet prefix. it's giving helpful bestie energy π - The
CIDRclass now also supports abbreviated CIDR ranges and uses older classful network address rules to decide on a subnet prefix if one is not explicitly provided. Supported forms now include10,10/8and192.168/16. Currently only supports these options for IPv4 CIDR address ranges. __repr__()methods have been defined for all classes in thenetaddrmodule, producing executable Python statements that can be used to re-create the state of any object.CIDRandWildcardclasses now have methods that support conversions between these two aggregate types :-- CIDR -> Wildcard
- Wildcard -> CIDR
Housekeeping Changes
- Massive docstring review and tidy up, with the inclusion of epydoc specific syntax to spruce up auto-generated API documentation. π§Ή
- Thorough review of code using
pylint. netaddrmodule now has the special__version__variable defined, which is also referenced bysetup.py.- Some minor changes to
setup.pyandMANIFEST.in. - Constants and custom Exception classes have been moved to
__init__.pyfromstrategy.py - An
import *friendly__all__has been defined for thenetaddrnamespace which should remove the need to delve too much into the address and strategy submodules. - Fixed a number of line-ending issues in several files. π
π COPYRIGHT
Here are the copyright notices applicable to the netaddr library.
netaddr
Copyright (c) 2008 David P. D. Moss Portions Copyright (c) 2020 netaddr contributors
Released under the BSD license. See the LICENSE file for details.
IANA (Internet Assigned Numbers Authority)
netaddr is not sponsored nor endorsed by IANA.
Use of data from IANA (Internet Assigned Numbers Authority) is subject to copyright and is provided with prior written permission.
IANA data files included with netaddr are not modified in any way but are parsed and made available to end users through an API.
See README file and source code for URLs to latest copies of the relevant files.
IEEE (Institution of Electrical Engineers)
netaddr is not sponsored nor endorsed by the IEEE.
Use of data from the IEEE (Institute of Electrical and Electronics Engineers) is subject to copyright. See the following URL for details :
http://www.ieee.org/web/publications/rights/legal.html
IEEE data files included with netaddr are not modified in any way but are parsed and made available to end users through an API. There is no guarantee that referenced files are not out of date.
See README file and source code for URLs to latest copies of the relevant files.
π LICENSE
ok so this is the part where we get β¨legalβ¨ β here's every license that applies when you use the netaddr library. read it, love it, respect it π
netaddr
COPYRIGHT AND LICENSE
Real talk, bestie β this next bit is the actual legal text and it is not getting a glow-up, because that's literally the whole point of legal text. Copying it exactly:
Copyright (c) 2008 David P. D. Moss Portions Copyright (c) 2020 netaddr
contributors
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
And the three conditions β these are non-negotiable, no cap:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of David P. D. Moss nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
Then the big one β the disclaimer. it's giving "we are not responsible for your chaos" π and every word of it matters:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
π AUTHORS
the actual masterminds behind this whole thing:
- David P. D. Moss (author, maintainer) <drkjam@gmail.com>
- Stefan Nordhausen (maintainer) <stefan.nordhausen@immobilienscout24.de>
- Jakub Stasiak (maintainer) <jakub@stasiak.at>
Released under the BSD License (see License <> for details).
π«Ά CONTRIBUTORS
ok so netaddr is written by David P. D. Moss and is currently maintained by Jakub Stasiak β shoutout to the main characters π₯
It is released under the BSD License.
And listen β so many people further contributed to netaddr by reporting problems, suggesting various improvements or submitting actual code. Here's the list of these people (in alphabetical order). And the page literally asks: help keep it complete and free of errors. so if your name belongs here, say something!! π₯Ί
- Vincent Bernat <bernat AT debian.org>
- Sebastien Douche <sdouche AT gmail.com>
- John Eckersberg <john DOT eckersberg AT gmail.com>
- Yi-Jheng Lin <yzlin AT cs.nctu.edu.tw>
- Clay McClure <clay AT daemons.net>
- Duncan McGreggor <duncan DOT mcgreggor AT gmail.com>
- Stefan Nordhausen <stefan DOT nordhausen AT axiros.com>
- Brian F. Peters <brianfpeters AT gmail.com>
- James William Pye <jwp AT gmail.com>
- Chaitan Rogers <chaitan DOT rogers AT gmail.com>
- Victor Stinner <victor DOT stinner AT haypocalc.com>
- Andrew Stromnov <stromnov AT gmail.com>
Thanks to everyone on the netaddr mailing list, those who raised bug reports and to all those who have, directly and indirectly, guided and influenced the development and distribution of this library π
Also β thanks for the use of these code contributions, iconic behaviour honestly:
a. Python Cookbook recipe 18.11: "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 Recipe 466286: "Integer set type" by Heiko Wundram <http://code.activestate.com/recipes/466286/>
And last but not least β thanks to Guido van Rossum for his encouraging words and for giving us all Python π periodt
π INDICES AND TABLES
- Index <>
- Search Page <>
Author
David P. D. Moss
Copyright
2008 David P. D. Moss, 2020 netaddr contributors
and that's a wrap on the whole page, bestie!! π this was netaddr 1.3.0, dated Dec 14, 2025 β go forth, format your integers as binary strings, and slay π
β¨π¦
π¦ where this page comes from
- arch rolling: python-netaddr 1.3.0-2 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms