Exemplo n.º 1
0
        /// <summary>
        /// Tries to parse the string as an IPAddress.  If that fails, it will resolve
        /// it as a host name and select the best address using the given priority query.
        /// </summary>
        /// <param name="ipOrHost">An ip address or host name</param>
        /// <param name="dnsPriorityQuery">Callback that determines priority to select an address from Dns record.
        ///   Use DnsPriority.(QueryName) for standard queries.</param>
        /// <returns>The parsed or resolved ip address.</returns>
        public static IPAddress ParseIPOrResolveHost(String ipOrHost, PriorityQuery <IPAddress> dnsPriorityQuery)
        {
            IPAddress ip;

            if (IPParser.TryParse(ipOrHost, out ip))
            {
                return(ip);
            }
            return(DnsResolve(ipOrHost, dnsPriorityQuery));
        }
Exemplo n.º 2
0
        public StringEndPoint(String ipOrHost, UInt16 port)
        {
            this.ipOrHost = ipOrHost;
            this.port     = port;

            IPAddress ip;

            if (IPParser.TryParse(ipOrHost, out ip))
            {
                this.stringIsAnIP = true;
                this.ipEndPoint   = new IPEndPoint(ip, port);
            }
            else
            {
                this.stringIsAnIP = false;
                this.ipEndPoint   = null;
            }
        }