I am looking for a PHP algorithm/script

Discussion in 'other software & services' started by Tech Manager, Sep 30, 2008.

Thread Status:
Not open for further replies.
  1. Tech Manager

    Tech Manager Registered Member

    Jan 7, 2008
    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: - 974258176 - 974323711 - 974323712 - 974389247 - 974389248 - 974454783 - 974454784 - 974520319 - 974520320 - 974651391 - 974651392 - 974782463 - 975044608 - 975175679 - 975175680 - 975699967 - 975699968 - 975831039 - 975831040 - 975896575 - 975896576 - 975962111 - 975962112 - 976224255 - 976224256 - 976748543 - 976748544 - 976879615 - 976879616 - 976945151 - 976945152 - 976977919 - 976977920 - 977010687 - 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

    The second group of 12 ranges should aggregate to two IP Blocks: and

    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.
  2. Stem

    Stem Firewall Expert

    Oct 5, 2005

    I cannot help you with a script etc.

    I use the blocklist manager to aggregate various IP lists. Maybe someone over at their forums could help you with a script

    - Stem
Thread Status:
Not open for further replies.