/// <summary> /// Create a new range from a begin and end address. /// Throws an exception if Begin comes after End, or the /// addresses are not in the same family. /// </summary> public IPAddressRange(IPAddress begin, IPAddress end) { if (begin == null) { throw new ArgumentNullException("begin"); } if (end == null) { throw new ArgumentNullException("end"); } Begin = begin; End = end; if (Begin.AddressFamily != End.AddressFamily) { throw new ArgumentException("Elements must be of the same address family", "beginEnd"); } var beginBytes = Begin.GetAddressBytes(); var endBytes = End.GetAddressBytes(); if (!Bits.LE(endBytes, beginBytes)) { throw new ArgumentException("Begin must be smaller than the End", "beginEnd"); } }
public bool Contains(IPAddress ipaddress) { if (ipaddress.AddressFamily != this.Begin.AddressFamily) { return(false); } var adrBytes = ipaddress.GetAddressBytes(); return(Bits.GE(this.Begin.GetAddressBytes(), adrBytes) && Bits.LE(this.End.GetAddressBytes(), adrBytes)); }
public bool Contains(IPAddressRange range) { if (this.Begin.AddressFamily != range.Begin.AddressFamily) { return(false); } return (Bits.GE(this.Begin.GetAddressBytes(), range.Begin.GetAddressBytes()) && Bits.LE(this.End.GetAddressBytes(), range.End.GetAddressBytes())); throw new NotImplementedException(); }
public bool Contains(IPAddress ipaddress) { if (ipaddress == null) { throw new ArgumentNullException("ipaddress"); } if (ipaddress.AddressFamily != this.Begin.AddressFamily) { return(false); } var adrBytes = ipaddress.GetAddressBytes(); return(Bits.GE(this.Begin.GetAddressBytes(), adrBytes) && Bits.LE(this.End.GetAddressBytes(), adrBytes)); }