Wednesday 21 January 2009

netaddr 0.6 released

For those who are interested netaddr 0.6 has just been released.

A couple of nights ago, I hit a very important personal milestone.

One of the killer features I've wanted since starting on netaddr back in January of 2008 is now in the bag! It ended up being one of the more tricky problems I've had to deal with but has been worth the effort. It will also prove extremely useful in my day-to-day work.

Essentially, you can now take an arbitrary start and end IP address (versions 4 and 6), and formulate a list of intervening CIDRs that exactly bridge the two with no overlaps.

A lot of infrastructure code had to be built before I was at a point where this could be implemented elegantly. The wait is (finally) over. It has also allowed me to kill some really ugly code based on math.frexp() which didn't work for IPv6 as it died somewhere around 2^54 due to rounding issues.

So, here is the result of the (worst case) scenario in the IPv4 address space (IPv6 would take up too much screen space) :-

In [1]: from netaddr import *

In [2]: cidrs = IPRange('0.0.0.1', '255.255.255.254').cidrs()

In [3]: print "\n".join(["%-18s: %-15s -> %-15s" % (str(c), c[0], c[-1]) for c in cidrs])
0.0.0.1/32 : 0.0.0.1 -> 0.0.0.1
0.0.0.2/31 : 0.0.0.2 -> 0.0.0.3
0.0.0.4/30 : 0.0.0.4 -> 0.0.0.7
0.0.0.8/29 : 0.0.0.8 -> 0.0.0.15
0.0.0.16/28 : 0.0.0.16 -> 0.0.0.31
0.0.0.32/27 : 0.0.0.32 -> 0.0.0.63
0.0.0.64/26 : 0.0.0.64 -> 0.0.0.127
0.0.0.128/25 : 0.0.0.128 -> 0.0.0.255
0.0.1.0/24 : 0.0.1.0 -> 0.0.1.255
0.0.2.0/23 : 0.0.2.0 -> 0.0.3.255
0.0.4.0/22 : 0.0.4.0 -> 0.0.7.255
0.0.8.0/21 : 0.0.8.0 -> 0.0.15.255
0.0.16.0/20 : 0.0.16.0 -> 0.0.31.255
0.0.32.0/19 : 0.0.32.0 -> 0.0.63.255
0.0.64.0/18 : 0.0.64.0 -> 0.0.127.255
0.0.128.0/17 : 0.0.128.0 -> 0.0.255.255
0.1.0.0/16 : 0.1.0.0 -> 0.1.255.255
0.2.0.0/15 : 0.2.0.0 -> 0.3.255.255
0.4.0.0/14 : 0.4.0.0 -> 0.7.255.255
0.8.0.0/13 : 0.8.0.0 -> 0.15.255.255
0.16.0.0/12 : 0.16.0.0 -> 0.31.255.255
0.32.0.0/11 : 0.32.0.0 -> 0.63.255.255
0.64.0.0/10 : 0.64.0.0 -> 0.127.255.255
0.128.0.0/9 : 0.128.0.0 -> 0.255.255.255
1.0.0.0/8 : 1.0.0.0 -> 1.255.255.255
2.0.0.0/7 : 2.0.0.0 -> 3.255.255.255
4.0.0.0/6 : 4.0.0.0 -> 7.255.255.255
8.0.0.0/5 : 8.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/2 : 128.0.0.0 -> 191.255.255.255
192.0.0.0/3 : 192.0.0.0 -> 223.255.255.255
224.0.0.0/4 : 224.0.0.0 -> 239.255.255.255
240.0.0.0/5 : 240.0.0.0 -> 247.255.255.255
248.0.0.0/6 : 248.0.0.0 -> 251.255.255.255
252.0.0.0/7 : 252.0.0.0 -> 253.255.255.255
254.0.0.0/8 : 254.0.0.0 -> 254.255.255.255
255.0.0.0/9 : 255.0.0.0 -> 255.127.255.255
255.128.0.0/10 : 255.128.0.0 -> 255.191.255.255
255.192.0.0/11 : 255.192.0.0 -> 255.223.255.255
255.224.0.0/12 : 255.224.0.0 -> 255.239.255.255
255.240.0.0/13 : 255.240.0.0 -> 255.247.255.255
255.248.0.0/14 : 255.248.0.0 -> 255.251.255.255
255.252.0.0/15 : 255.252.0.0 -> 255.253.255.255
255.254.0.0/16 : 255.254.0.0 -> 255.254.255.255
255.255.0.0/17 : 255.255.0.0 -> 255.255.127.255
255.255.128.0/18 : 255.255.128.0 -> 255.255.191.255
255.255.192.0/19 : 255.255.192.0 -> 255.255.223.255
255.255.224.0/20 : 255.255.224.0 -> 255.255.239.255
255.255.240.0/21 : 255.255.240.0 -> 255.255.247.255
255.255.248.0/22 : 255.255.248.0 -> 255.255.251.255
255.255.252.0/23 : 255.255.252.0 -> 255.255.253.255
255.255.254.0/24 : 255.255.254.0 -> 255.255.254.255
255.255.255.0/25 : 255.255.255.0 -> 255.255.255.127
255.255.255.128/26: 255.255.255.128 -> 255.255.255.191
255.255.255.192/27: 255.255.255.192 -> 255.255.255.223
255.255.255.224/28: 255.255.255.224 -> 255.255.255.239
255.255.255.240/29: 255.255.255.240 -> 255.255.255.247
255.255.255.248/30: 255.255.255.248 -> 255.255.255.251
255.255.255.252/31: 255.255.255.252 -> 255.255.255.253
255.255.255.254/32: 255.255.255.254 -> 255.255.255.254

I am now officially proud of this project ;-)

Friday 16 January 2009

"Not Invented Here" is a powerful force

A link to this 2006 blog post came up on my feeds recently :-

http://blog.pythonisito.com/2006/01/three-reasons-why-you-shouldnt-write.html

It's a great article (with excellent commentary) on reasons for (and against) starting your own code project versus joining an existing one. Things are certainly not as clear cut as they might appear at first. It uses the umpteenth Python web frameworks spawned (prior to the arrival of Django) as a basis for discussion but is good general advice for those thinking about contributing to the pool of open source software.

Certainly food for thought.