11 private readonly IPAddress address;
12 private readonly
byte[] binary;
13 private readonly
int range;
58 int i = s.IndexOf(
'/');
68 s = s.Substring(0, i);
71 if (!IPAddress.TryParse(s, out IPAddress
Address))
74 byte[] Bin =
Address.GetAddressBytes();
75 int MaxRange = Bin.Length << 3;
79 else if (
Range > MaxRange)
94 if (IPAddress.TryParse(Endpoint.RemovePortNumber(), out IPAddress
Address))
107 if (
Address.AddressFamily !=
this.address.AddressFamily)
110 byte[] Bin =
Address.GetAddressBytes();
111 int i, c = Math.Min(this.binary.Length, Bin.Length);
112 int Bits = this.range;
115 for (i = 0; i < c && Bits > 0; i++, Bits -= 8)
120 Mask = (byte)(0xff << (8 - Bits));
122 if (((this.binary[i] ^ Bin[i]) & Mask) != 0)
IP Address Rangee, expressed using CIDR format.
bool Matches(IPAddress Address)
Checks if an IP Address matches the defined range.
static bool TryParse(string s, out IpCidr Parsed)
Tries to parse an IP Range in CIDR format. (An IP Address alone is considered implicitly having a mas...
IpCidr(IPAddress Address, int Range)
IP Address Rangee, expressed using CIDR format.
bool Matches(string Endpoint)
Checks if an IP Address matches the defined range.
IPAddress Address
Parsed IP Address