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 (
Address.AddressFamily !=
this.address.AddressFamily)
97 byte[] Bin =
Address.GetAddressBytes();
98 int i, c = Math.Min(this.binary.Length, Bin.Length);
99 int Bits = this.range;
102 for (i = 0; i < c && Bits > 0; i++, Bits -= 8)
107 Mask = (byte)(0xff << (8 - Bits));
109 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.
IPAddress Address
Parsed IP Address
IpCidr(IPAddress Address, int Range)
IP Address Rangee, expressed using CIDR format.
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...