A Blog Less Ordinary

The blog of Dave Ingram

Map of the Internet

So, I got to thinking about xkcd‘s famous (or infamous) map of the IPv4 address space. And, naturally, I wondered if I could write a program to draw it. After looking around on their forums, I found an algorithm or two which seem to do this, and all it needs is the input list of integers. So the algorithm (in fact, a plethora of them) exists and is straightforward… probably even fast. All that needs to happen now is to hook it up to GD or something similar and watch it draw.

Then I started worrying.

IPv4 is relatively small, but it’s actually very big, isn’t it? How much space would this image take?

Well there are 232 possible addresses in IPv4. The Hilbert curve ends up with a square, so that’s 2^16 pixels per side. But wait; it’s a space-filling curve. That means we need to double the dimensions to have a 1px gap between each part. And add an extra pixel for a nice 1px border all round. That’s 2^17+1 pixels per side. Now, let’s decide to use four colours in our diagram. There’s the background colour (e.g. white), the line colour (grey), the allocated address colour (red) and the unallocated address colour (green). So, at 4 bits per pixel, we want to store (2^17+1)^2 pixels, or ((2^17+1)^2)/2 bytes. That works out as being 8,590,065,665 bytes or so. Ignoring headers. That’s almost exactly 8GiB.

So, say, after generating this huge 8GiB bitmap, we decide we want to print it. At, let’s say, 300dpi (which is a fairly high resolution for printers, or at least it used to be). It works out that the image would therefore be just under 437 inches each way, or just under 36.5 feet, or about 12 yards (or approx 11.1m if you’re feeling metric). That’s a pretty big picture. Even at twice the resolution, it’s 6 yards (5.55m) on a side. Chances are, at that fine a dot size, you wouldn’t be able to make out the individual addresses anyway!

So why did I work this out? I was bored.

It might still be fun to do…

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

 

GitHub Google+ Twitter