I`m working on a project using TypeScript and have access to a key-value based storage. The requirement is to find data related to a single IP (match key).
Unfortunately the key is always a CIDR covering a lot of IP's (to save storage due to many records). During my tests I was unable to find the correct CIDR belonging to a specific IP.
Example data:
"103.21.244.0/24" - "data, lorem ipsum, etc"
Example IP to find:
"103.21.244.1"
I have tested several libraries like: ip-address, ip-num, ip-to-int, ipaddr.js and more, but I am unable to get the result I want.
Maybe I am just being dumb and do not understand the IP specification correctly, or maybe I am just misusing these libraries, please enlighten me.
Surely there has to be a way without calling external API's (like RIPE) and without having to store billions of IP's instead of their CIDR.
Essentially the requirement is quite simple: "find this KEY (in CIDR) by this IP (v4 or v6)".
Any help, advice, example solutions are highly appreciated.