I am a professional PHP programmer experiencing brain freeze.
I am looking for a script/algorithm that I can interface with a database to create consolidated/aggregated IP blocks.
Here is the issue:
I own and run Country IP Blocks. This site provides highly accurate network information on nearly 250 countries around the world. Data is pulled from one of our several databases to produce a wide variety of ACL's, such as CIDR, dotted-decimal, .htaccess deny & allow and other lists as needed.
I've been contacted by several network administrators asking if we would begin distributing consolidated/aggregated IP Blocks to allow for easier development of specific firewall rules. In other words, aggregation of contiguous IP blocks would provide the option for shorter lists. Normally I would program this myself, but with my current heavy schedule and temporary brain freeze I thought I would ask if any of you know of a PHP solution to solve this problem.
Basically what we want to do is to pull continguous IP blocks from the database, aggregate them and present the results.
Here's an example of a few blocks from China:
58.18.0.0/16 58.18.0.0 - 58.18.255.255 974258176 - 974323711
58.19.0.0/16 58.19.0.0 - 58.19.255.255 974323712 - 974389247
58.20.0.0/16 58.20.0.0 - 58.20.255.255 974389248 - 974454783
58.21.0.0/16 58.21.0.0 - 58.21.255.255 974454784 - 974520319
58.22.0.0/15 58.22.0.0 - 58.23.255.255 974520320 - 974651391
58.24.0.0/15 58.24.0.0 - 58.25.255.255 974651392 - 974782463
58.30.0.0/15 58.30.0.0 - 58.31.255.255 975044608 - 975175679
58.32.0.0/13 58.32.0.0 - 58.39.255.255 975175680 - 975699967
58.40.0.0/15 58.40.0.0 - 58.41.255.255 975699968 - 975831039
58.42.0.0/16 58.42.0.0 - 58.42.255.255 975831040 - 975896575
58.43.0.0/16 58.43.0.0 - 58.43.255.255 975896576 - 975962111
58.44.0.0/14 58.44.0.0 - 58.47.255.255 975962112 - 976224255
58.48.0.0/13 58.48.0.0 - 58.55.255.255 976224256 - 976748543
58.56.0.0/15 58.56.0.0 - 58.57.255.255 976748544 - 976879615
58.58.0.0/16 58.58.0.0 - 58.58.255.255 976879616 - 976945151
58.59.0.0/17 58.59.0.0 - 58.59.127.255 976945152 - 976977919
58.59.128.0/17 58.59.128.0 - 58.59.255.255 976977920 - 977010687
58.60.0.0/14 58.60.0.0 - 58.63.255.255 977010688 - 977272831
The data in the tables actually appears in decimal ( the right columns) as opposed to dotted decimal.
Looking at the above info we want to produce aggregated results. So, doing some quick math the first 6 IP ranges should aggregate to 58.18.0.0/13.
The second group of 12 ranges should aggregate to two IP Blocks: 58.30.0.0/11 and 58.62.0.0/15.
As you can see, this significantly reduces the output. The end result is the option of shorter lists and less memory/cpu required to run them on respective firewalls.
I am in need of a PHP script that can be modified as needed to produce similar results. If you are aware of such a script please let me know. Perhaps we could work out a suitable trade.
I recommend Country IP Blocks dot net as part of your security arsenal.
Bookmarks