2

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

INFOSYS
  • 1,465
  • 9
  • 23
  • 50
  • What´s wrong with linear comparisson? Unless you have over 1 million ranges shouldn´t be a great concern – juvian Sep 13 '17 at 17:28
  • @juvian just to confess it is a ad server blacklist ips and here i need to get it done in a matter of milliseconds and the data will get added here i:e more ip ranges in future. and there are other processes to too related to ad serving so this needs to be quick – INFOSYS Sep 13 '17 at 17:29
  • Can there be multiple matches? – juvian Sep 13 '17 at 17:31
  • no it should happen , i just need to give like a true and false does it exists in the ip range ot not – INFOSYS Sep 13 '17 at 17:31
  • If they are non overlapping ranges you can convert them to number ranges, keep them sorted and then each query can be made in log n comparissons, but you would need to keep all in memory – juvian Sep 13 '17 at 17:36
  • sorting and keeping it in memory is another reason i need to use some other techniques, because i will fetch it from db and want to just run a query on that array of objects – INFOSYS Sep 13 '17 at 17:40
  • This is probably what you are looking for: https://stackoverflow.com/questions/1193477/fast-algorithm-to-quickly-find-the-range-a-number-belongs-to-in-a-set-of-ranges – Nelson Yeung Sep 13 '17 at 17:44
  • Well if you are using a db then you can store them as number ranges and your db query would already search between the ranges – juvian Sep 13 '17 at 17:45
  • sorry @juvian i mistook in memory this list be pouplated only one at model build stored as apart of the build in model , i dnt want to overprocess the model – INFOSYS Sep 13 '17 at 17:47
  • Did not understand, do you make 1 db query for each ip you want to check or you retrieve all from db once and then process each ip you want to check – juvian Sep 13 '17 at 18:06

0 Answers0