InternalGetHostByName() private static method

private static InternalGetHostByName ( string hostName, bool includeIPv6 ) : IPHostEntry
hostName string
includeIPv6 bool
return IPHostEntry
Beispiel #1
0
        public string dnsResolve(string host)
        {
            GlobalLog.Print("WebProxyScriptHelper::dnsResolve() host:" + ValidationHelper.ToString(host));
            if (host == null)
            {
                if (Logging.On)
                {
                    Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_called_with_null_parameter, "WebProxyScriptHelper.dnsResolve()", "host"));
                }
                throw new ArgumentNullException("host");
            }
            IPHostEntry ipHostEntry = null;

            try
            {
                ipHostEntry = Dns.InternalGetHostByName(host);
            }
            catch { }
            if (ipHostEntry == null)
            {
                return(string.Empty);
            }
            for (int i = 0; i < ipHostEntry.AddressList.Length; i++)
            {
                if (ipHostEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                {
                    return(ipHostEntry.AddressList[i].ToString());
                }
            }
            return(string.Empty);
        }
Beispiel #2
0
        public bool isResolvableEx(string host)
        {
            if (host == null)
            {
                if (Logging.On)
                {
                    Logging.PrintWarning(Logging.Web, SR.GetString("net_log_proxy_called_with_null_parameter", new object[] { "WebProxyScriptHelper.dnsResolve()", "host" }));
                }
                throw new ArgumentNullException("host");
            }
            IPHostEntry hostByName = null;

            try
            {
                hostByName = Dns.InternalGetHostByName(host);
            }
            catch
            {
            }
            if (hostByName == null)
            {
                return(false);
            }
            if (hostByName.AddressList.Length == 0)
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public bool isResolvableEx(string host)
        {
            GlobalLog.Print("WebProxyScriptHelper::dnsResolveEx() host:" + ValidationHelper.ToString(host));
            if (host == null)
            {
                if (Logging.On)
                {
                    Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_called_with_null_parameter, "WebProxyScriptHelper.dnsResolve()", "host"));
                }
                throw new ArgumentNullException("host");
            }
            IPHostEntry ipHostEntry = null;

            try
            {
                ipHostEntry = Dns.InternalGetHostByName(host);
            }
            catch { }
            if (ipHostEntry == null)
            {
                return(false);
            }
            IPAddress[] addresses = ipHostEntry.AddressList;
            if (addresses.Length == 0)
            {
                return(false);
            }
            return(true);
        }
Beispiel #4
0
        public bool isResolvable(string host)
        {
            if (host == null)
            {
                if (Logging.On)
                {
                    Logging.PrintWarning(Logging.Web, SR.GetString("net_log_proxy_called_with_null_parameter", new object[] { "WebProxyScriptHelper.isResolvable()", "host" }));
                }
                throw new ArgumentNullException("host");
            }
            IPHostEntry hostByName = null;

            try
            {
                hostByName = Dns.InternalGetHostByName(host);
            }
            catch
            {
            }
            if (hostByName != null)
            {
                for (int i = 0; i < hostByName.AddressList.Length; i++)
                {
                    if (hostByName.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        //
        //
        //
        internal string GetComputeSpn(HttpWebRequest httpWebRequest)
        {
            if (ChallengedSpn != null)
            {
                return(ChallengedSpn);
            }

            string spnKey = httpWebRequest.ChallengedUri.GetParts(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped);
            string spn    = AuthenticationManager.SpnDictionary.InternalGet(spnKey);

            if (spn == null)
            {
                if (!IsProxyAuth && httpWebRequest.ServicePoint.InternalProxyServicePoint)
                {
                    // Here the NT-Security folks need us to attempt a DNS lookup to figure out
                    // the FQDN. only do the lookup for short names (no IP addresses or DNS names)
                    //
                    // Initialize a backup value
                    spn = httpWebRequest.ChallengedUri.Host;

                    if (httpWebRequest.ChallengedUri.HostNameType != UriHostNameType.IPv6 && httpWebRequest.ChallengedUri.HostNameType != UriHostNameType.IPv4 && spn.IndexOf('.') == -1)
                    {
                        try {
                            //



                            spn = Dns.InternalGetHostByName(spn).HostName;
                            GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::GetComputeSpn() Dns returned host:" + ValidationHelper.ToString(spn));
                        }
                        catch (Exception exception) {
                            if (NclUtilities.IsFatal(exception))
                            {
                                throw;
                            }
                            GlobalLog.Print("AuthenticationState#" + ValidationHelper.HashString(this) + "::GetComputeSpn() GetHostByName(host) failed:" + ValidationHelper.ToString(exception));
                        }
                    }
                }
                else
                {
                    // For this cases we already did a DNS lookup

                    //



                    spn = httpWebRequest.ServicePoint.Hostname;
                }
                spn    = "HTTP/" + spn;
                spnKey = httpWebRequest.ChallengedUri.GetParts(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped) + "/";
                AuthenticationManager.SpnDictionary.InternalSet(spnKey, spn);
            }
            return(ChallengedSpn = spn);
        }
Beispiel #6
0
        public string dnsResolveEx(string host)
        {
            if (host == null)
            {
                if (Logging.On)
                {
                    Logging.PrintWarning(Logging.Web, SR.GetString("net_log_proxy_called_with_null_parameter", new object[] { "WebProxyScriptHelper.dnsResolve()", "host" }));
                }
                throw new ArgumentNullException("host");
            }
            IPHostEntry hostByName = null;

            try
            {
                hostByName = Dns.InternalGetHostByName(host);
            }
            catch
            {
            }
            if (hostByName == null)
            {
                return(string.Empty);
            }
            IPAddress[] addressList = hostByName.AddressList;
            if (addressList.Length == 0)
            {
                return(string.Empty);
            }
            StringBuilder builder = new StringBuilder();

            for (int i = 0; i < addressList.Length; i++)
            {
                builder.Append(addressList[i].ToString());
                if (i != (addressList.Length - 1))
                {
                    builder.Append(";");
                }
            }
            if (builder.Length <= 0)
            {
                return(string.Empty);
            }
            return(builder.ToString());
        }
Beispiel #7
0
        public string dnsResolveEx(string host)
        {
            GlobalLog.Print("WebProxyScriptHelper::dnsResolveEx() host:" + ValidationHelper.ToString(host));
            if (host == null)
            {
                if (Logging.On)
                {
                    Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_called_with_null_parameter, "WebProxyScriptHelper.dnsResolve()", "host"));
                }
                throw new ArgumentNullException("host");
            }
            IPHostEntry ipHostEntry = null;

            try
            {
                ipHostEntry = Dns.InternalGetHostByName(host);
            }
            catch { }
            if (ipHostEntry == null)
            {
                return(string.Empty);
            }
            IPAddress[] addresses = ipHostEntry.AddressList;
            if (addresses.Length == 0)
            {
                return(string.Empty);
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < addresses.Length; i++)
            {
                sb.Append(addresses[i].ToString());
                if (i != addresses.Length - 1)
                {
                    sb.Append(";");
                }
            }
            return(sb.Length > 0 ? sb.ToString(): string.Empty);
        }
        internal string GetComputeSpn(HttpWebRequest httpWebRequest)
        {
            if (this.ChallengedSpn != null)
            {
                return(this.ChallengedSpn);
            }
            string parts    = httpWebRequest.ChallengedUri.GetParts(UriComponents.Path | UriComponents.SchemeAndServer, UriFormat.SafeUnescaped);
            string hostName = AuthenticationManager.SpnDictionary.InternalGet(parts);

            if (hostName == null)
            {
                if (!this.IsProxyAuth && (httpWebRequest.ServicePoint.InternalProxyServicePoint || httpWebRequest.UseCustomHost))
                {
                    hostName = httpWebRequest.ChallengedUri.Host;
                    if (((httpWebRequest.ChallengedUri.HostNameType != UriHostNameType.IPv6) && (httpWebRequest.ChallengedUri.HostNameType != UriHostNameType.IPv4)) && (hostName.IndexOf('.') == -1))
                    {
                        try
                        {
                            hostName = Dns.InternalGetHostByName(hostName).HostName;
                        }
                        catch (Exception exception)
                        {
                            if (NclUtilities.IsFatal(exception))
                            {
                                throw;
                            }
                        }
                    }
                }
                else
                {
                    hostName = httpWebRequest.ServicePoint.Hostname;
                }
                hostName = "HTTP/" + hostName;
                parts    = httpWebRequest.ChallengedUri.GetParts(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped) + "/";
                AuthenticationManager.SpnDictionary.InternalSet(parts, hostName);
            }
            return(this.ChallengedSpn = hostName);
        }