public static IPAddressRange BinarySearchRanges(IPAddress ipAddress, List <IPAddressRange> addressRanges) { if (ipAddress.AddressFamily != AddressFamily.InterNetwork || addressRanges == null) { return(null); } int num = 0; int count = addressRanges.Count - 1; while (num <= count) { int num1 = num + (count - num) / 2; IPAddressRange item = addressRanges[num1]; if (ipAddress.CompareTo(item.StartingIPAddress) >= 0) { if (ipAddress.CompareTo(item.EndingIPAddress) <= 0) { return(item); } num = num1 + 1; } else { count = num1 - 1; } } return(null); }
public bool Contains(IPAddress ipAddress) { if (ipAddress.CompareTo(this.StartingIPAddress) < 0) { return(false); } return(ipAddress.CompareTo(this.EndingIPAddress) <= 0); }
public void IPAddressExtensions_CompareTo_AddressFamily() { IPAddress ipAddress1 = IPAddress.Parse("1.2.3.4"); IPAddress ipAddress2 = IPAddress.Parse("2.3.4.5"); IPAddress ipAddressV6 = IPAddress.IPv6None; ipAddress1.CompareTo(ipAddress2).Should().BeLessThan(0); ipAddress2.CompareTo(ipAddress1).Should().BeGreaterThan(0); ipAddress1.CompareTo(ipAddress1).Should().Be(0); ipAddress1.CompareTo(ipAddressV6).Should().BeLessThan(0); }
public TcpTuple(IPAddress srcAddress, ushort srcPort, IPAddress dstAddress, ushort dstPort) : base(SocketType.Stream, srcAddress, srcPort, dstAddress, dstPort) { var cmp = srcAddress.CompareTo(dstAddress); if (cmp == 0) { cmp = srcPort.CompareTo(dstPort); } if (cmp > 0) { AddressA = dstAddress; PortA = dstPort; AddressB = srcAddress; PortB = srcPort; } else { AddressA = srcAddress; PortA = srcPort; AddressB = dstAddress; PortB = dstPort; } }
public Int32 CompareTo(DeviceViewModel value) { if (this.Equals(value)) { return(0); } DeviceViewModel d1 = this; DeviceViewModel d2 = value; int result = 0; result = d1.Kind.CompareTo(d2.Kind); if ((d1.Kind == DeviceKind.NET) && (d2.Kind == DeviceKind.NET)) { string[] parts1 = d1.Path.Split(':'); string[] parts2 = d2.Path.Split(':'); IPAddress ip1 = IPAddress.Parse(parts1[0]); IPAddress ip2 = IPAddress.Parse(parts2[0]); if (ip1.Equals(ip2)) { result = int.Parse(parts1[1]).CompareTo(int.Parse(parts2[1])); } else { result = ip1.CompareTo(ip2); } } if (result == 0) { result = d1.Driver.CompareTo(d2.Driver); } if (result == 0) { result = d1.Name.CompareTo(d2.Name); } if (result == 0) { result = d1.Path.CompareTo(d2.Path); } if (result == 0) { result = d1.RelativeIndex.CompareTo(d2.RelativeIndex); } return(result); }
/// <summary> /// Compares two instances of this object. /// </summary> /// <param name="IPSocket">An object to compare with.</param> /// <returns>true|false</returns> public Int32 CompareTo(IPSocket IPSocket) { if (((Object)IPSocket) == null) { throw new ArgumentNullException(nameof(IPSocket), "The given IP socket must not be null!"); } var __IPAddress = IPAddress.CompareTo(IPSocket.IPAddress); if (__IPAddress != 0) { return(__IPAddress); } return(Port.CompareTo(IPSocket.Port)); }
public IPAddressRange(IPAddress startAddress, IPAddress endAddress) { if (startAddress == null) { throw new ArgumentNullException("startAddress"); } if (endAddress == null) { throw new ArgumentNullException("endAddress"); } this.StartingIPAddress = startAddress; this.EndingIPAddress = endAddress; if (startAddress.CompareTo(endAddress) > 0) { throw new ArgumentOutOfRangeException("startAddress", this.StartingIPAddress, "The startAddress must not exceed the endAddress."); } }
/// <summary> /// Compares to. /// </summary> /// <param name="other">The other.</param> /// <returns>System.Int32.</returns> /// <autogeneratedoc /> public int CompareTo(IPAddressSubnet other) { return(other == null ? 1 : IPAddress.CompareTo(other.IPAddress)); // Ignore Subnet Masks, Just compare IPAddress }
public static bool LessThanOrEqual(this IPAddress ipAddress, IPAddress toCompare) { return(ipAddress.CompareTo(toCompare) <= 0); }
public static bool GreaterThanOrEqual(this IPAddress ipAddress, IPAddress toCompare) { return(ipAddress.CompareTo(toCompare) >= 0); }