作者在 2006-08-25 17:07:00 发布以下内容
using System; using System.Net; namespace LoweSoftware.Tools { /// <summary> /// Used to convert and compare IP addresses. /// /// By Alexander Lowe, Lowe*Software. /// http://www.lowesoftware.com /// /// Free for use and modification. No warranty express or /// implied. /// </summary> class IPCompare { /// <summary> /// Compares two IP addresses for equality. /// </summary> /// <param name="IPAddr1">The first IP to compare</param> /// <param name="IPAddr2">The second IP to compare</param> /// <returns>True if equal, false if not.</returns> static public bool AreEqual(string IPAddr1, string IPAddr2) { // convert to long in case there is any zero padding in // the strings return IPAddressToLongBackwards(IPAddr1)== sIPAddressToLongBackwards(IPAddr2); } /// <summary> /// Compares two string representations of an Ip address to /// see if one is greater than the other /// </summary> /// <param name="ToCompare">The IP address on the left hand /// side of the greater than operator</param> /// <param name="CompareAgainst">The Ip address on the right /// hand side of the greater than operator</param> /// <returns>True if ToCompare is greater than CompareAgainst, /// else false</returns> static public bool IsGreater(string ToCompare, string CompareAgainst) { // convert to long in case there is any zero padding in // the strings return IPAddressToLongBackwards(ToCompare)> IPAddressToLongBackwards(CompareAgainst); } /// <summary> /// Compares two string representations of an Ip address to /// see if one is less than the other /// </summary> /// <param name="ToCompare">The IP address on the left hand /// side of the less than operator</param> /// <param name="CompareAgainst">The Ip address on the right /// hand side of the less than operator</param> /// <returns>True if ToCompare is greater than CompareAgainst, /// else fa