IpAddressFilter

Ecng.Net

Reusable IP address filter supporting exact addresses and CIDR subnet masks. Thread-safe, immutable after construction.

Constructors

IpAddressFilter
public IpAddressFilter(string restrictions)
ipAddressFilter = IpAddressFilter(restrictions)

Creates filter from comma-separated string of IPs and/or CIDR masks. Example: "192.168.1.1, 10.0.0.0/8, 2001:db8::/32"

IpAddressFilter
public IpAddressFilter(IEnumerable<string> restrictions)
ipAddressFilter = IpAddressFilter(restrictions)

Creates filter from enumerable of IP/CIDR strings.

Properties

IsEmpty
public bool IsEmpty { get; }
value = ipAddressFilter.IsEmpty

Returns true if the filter has no restrictions (empty list = allow all).

Methods

IsAllowed
public bool IsAllowed(IPAddress address)
result = ipAddressFilter.IsAllowed(address)

Check if address is allowed by this filter. Returns true if address matches any exact IP or falls within any CIDR range. Loopback addresses (127.0.0.1, ::1) are always treated as matching each other.