static public int CompareFor(System.Net.IPAddress x, System.Net.IPAddress y) { if ((x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && y.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) || (x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 && y.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)) { return(IPSeg.CompareFor(x.GetAddressBytes(), y.GetAddressBytes())); } throw new Exception("IP地址类型必须是IPv4或者IPv6才能进行比较"); }
public bool In(System.Net.IPAddress addr) { if (IsNull(from_)) { return(false); } if (IsNull(to_)) { return(0 == IPSeg.CompareFor(From, addr)); } if (IPSeg.CompareFor(From, addr) > 0) { return(false); } return(IPSeg.CompareFor(To, addr) >= 0); }
public IEnumerator <System.Net.IPAddress> internalGetEnumerator() { if (!IsNull(from_)) { if (IsNull(to_)) { yield return(From); } else { System.Net.IPAddress from = From; while (true) { yield return(from); if (IPSeg.CompareFor(from, To) >= 0) { break; } from = IPSeg.Next(from); } } } }