/// <summary>
        ///     Determines whether a string is a valid IP address.
        /// </summary>
        /// <returns>
        ///     true if <paramref name="ipString" /> is a valid IP address; otherwise, false.
        /// </returns>
        /// <param name="ipString">The string to validate.</param>
        /// <param name="address">The <see cref="SingleIP" /> version of the string.</param>
        public static bool TryParse(string ipString, out SingleIP address)
        {
            if (ipString.Trim() == "*")
            {
                address = Any;
                return(true);
            }
            IPAddress ipAddress;

            if (IPAddress.TryParse(ipString, out ipAddress))
            {
                address = FromIPAddress(ipAddress);
                return(true);
            }
            var ips = ipString.Split('-');

            if (ips.Length == 2)
            {
                IPAddress address1;
                IPAddress address2;
                if (IPAddress.TryParse(ips[0], out address1) && IPAddress.TryParse(ips[1], out address2))
                {
                    if (address1.Equals(address2))
                    {
                        address = FromIPAddress(address1);
                        return(true);
                    }
                }
            }
            address = null;
            return(false);
        }
Example #2
0
        /// <summary>
        ///     Determines whether a string is a valid IP address.
        /// </summary>
        /// <returns>
        ///     true if <paramref name="ipString" /> is a valid IP address; otherwise, false.
        /// </returns>
        /// <param name="ipString">The string to validate.</param>
        /// <param name="address">The <see cref="SingleIP" /> version of the string.</param>
        public static bool TryParse(string ipString, out SingleIP address)
        {
            if (ipString.Trim() == "*")
            {
                address = Any;
                return(true);
            }
            IPAddress ipAddress;

            if (IPAddress.TryParse(ipString, out ipAddress))
            {
                address = FromIPAddress(ipAddress);
                return(true);
            }
            address = null;
            return(false);
        }
 /// <summary>
 ///     Indicates whether the specified IP address is the loopback address.
 /// </summary>
 /// <returns>
 ///     true if <paramref name="address" /> is the loopback address; otherwise, false.
 /// </returns>
 /// <param name="address">An IP address. </param>
 public static bool IsLoopback(SingleIP address)
 {
     return(IPAddress.IsLoopback(address.ToIPAddress()));
 }