Using Classic ASP, I want to check if a given IP is within an IP range in CIDR (e.g. 192.168.0.0/24).
Some examples would be:
192.168.0.1
belongs to192.168.0.0/24
? (yes)192.168.0.100
belongs to192.168.0.0/24
? (yes)192.168.0.130
belongs to192.168.0.0/25
? (no! this one is192.168.0.0-192.168.0.127
)
And, of course, going out with the bitmasks from /32
to /0
(well the latter one should say “yes” to everything)
The actual use case is to check if a CloudFlare-proxied connection claiming CF-Connecting-IP header is actually coming from CloudFlare by the list they provide of ipv4 endpoints.
I’ve searched far and wide, and basically what I found in Stackoverflow was about returning IP ranges, or regex-validating IPs, so they either not help in my case, or were way cumbersome to base my code off.