/// <devdoc> /// Determines if the host Uri should be routed locally or go through the proxy. /// </devdoc> private bool IsLocal(Uri host) { string hostString = host.Host; IPAddress hostAddress; if (IPAddress.TryParse(hostString, out hostAddress)) { return(IPAddress.IsLoopback(hostAddress) || NclUtilities.IsAddressLocal(hostAddress)); } int dot = hostString.IndexOf('.'); // No dot? Local. if (dot == -1) { return(true); } // If it matches the primary domain, it's local. (Whether or not the hostname matches.) string local = "." + IPGlobalProperties.InternalGetIPGlobalProperties().DomainName; if (local != null && local.Length == (hostString.Length - dot) && string.Compare(local, 0, hostString, dot, local.Length, StringComparison.OrdinalIgnoreCase) == 0) { return(true); } return(false); }
private bool IsLocal(Uri host) { string ipString = host.Host; int indexB = -1; bool flag = true; bool flag2 = false; for (int i = 0; i < ipString.Length; i++) { if (ipString[i] == '.') { if (indexB != -1) { continue; } indexB = i; if (flag) { continue; } break; } if (ipString[i] == ':') { flag2 = true; flag = false; break; } if ((ipString[i] < '0') || (ipString[i] > '9')) { flag = false; if (indexB != -1) { break; } } } if ((indexB == -1) && !flag2) { return(true); } if (flag || flag2) { try { IPAddress address = IPAddress.Parse(ipString); return(IPAddress.IsLoopback(address) || NclUtilities.IsAddressLocal(address)); } catch (FormatException) { } } string strA = "." + IPGlobalProperties.InternalGetIPGlobalProperties().DomainName; return(((strA != null) && (strA.Length == (ipString.Length - indexB))) && (string.Compare(strA, 0, ipString, indexB, strA.Length, StringComparison.OrdinalIgnoreCase) == 0)); }
/// <devdoc> /// Determines if the host Uri should be routed locally or go through the proxy. /// </devdoc> private bool IsLocal(Uri host) { string hostString = host.Host; // If and only if the host has a colon or is all numbers and dots, it is an IP address. // If no dot, it is local. (If it has both a dot and a colon, undefined.) int dot = -1; bool isIp4 = true; bool isIp6 = false; for (int i = 0; i < hostString.Length; i++) { if (hostString[i] == '.') { if (dot == -1) { dot = i; if (!isIp4) { break; } } continue; } if (hostString[i] == ':') { isIp6 = true; isIp4 = false; break; } if (hostString[i] < '0' || hostString[i] > '9') { isIp4 = false; if (dot != -1) { break; } } } // No dot? Local. // The case of all digits is a little weird. Technically it could be a v4 IP, but practically it can only // be interpreted as an intranet name. if (dot == -1 && !isIp6) { return(true); } if (isIp4 || isIp6) { // I don't see why this would fail, but in case it does, it's not an IP. try { IPAddress hostAddress = IPAddress.Parse(hostString); if (IPAddress.IsLoopback(hostAddress)) { return(true); } return(NclUtilities.IsAddressLocal(hostAddress)); } catch (FormatException) { } } // If it matches the primary domain, it's local. (Whether or not the hostname matches.) string local = "." + IPGlobalProperties.InternalGetIPGlobalProperties().DomainName; if (local != null && local.Length == (hostString.Length - dot) && string.Compare(local, 0, hostString, dot, local.Length, StringComparison.OrdinalIgnoreCase) == 0) { return(true); } return(false); }