If I have an IP address range (CIDR notation) and I need to know if some arbitrary IP address is within that range — both presented as strings — what is the easiest way to do this with C#?
Examples:
- IPv4 Range:
192.168.168.100/24, IP to check:192.168.168.200 - IPv6 Range:
fe80::202:b3ff:fe1e:8329/24, IP to check:2001:db8::
Here’s a simple class:
Sample usage:
This class treats all IPv4 addresses as distinct from all IPv6 addresses, making no attempt to translate between IPv4 and IPv6.