I have aset of ip ranges and i need to find if the ip given by the user exists between the given list of ip ranges .
This is in continuation to this question
How to check if a given ip falls between a given ip range using node js
Jonas helped me get the ip exists or not. But i donot want to do a exhaustive iterative search , I want to go a fast performance intensive search as my list of ip ranges (or number ranges) will be huge.
I looked into bloom filters as pointed by jonas but i am not convinced bloom filter might help . Also i was looking at Interval Tree But i dnt think it can search interval it takes intervals as inputs.
My ip list ranges https://github.com/client9/ipcat/blob/master/datacenters.csv#L4
How to search it in a fast manner . I am using node js
Ive observated that many of your ips look like this:
So to filter them out, we just need to block every ip starting with:
Now there are just 16E6 ip ranges left for being blocked. However you will probably block just a few of them, which gives us the ability to store that in a Set. A bit of code:
So now there are just a few ranges that are not a block, like:
But hey, just 15 ips, which we can add to a ban by ip list:
So when iterating over our range list we can seperate:
To check if an ip fails the check