Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 9d87dde

Browse files
committed
proxyDnsRequests parameter in IsLocalIpAddress
1 parent 3740e6e commit 9d87dde

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/Titanium.Web.Proxy/Helpers/Network.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static bool IsLocalIpAddress(IPAddress address)
2727
return localhostEntry.AddressList.Contains(address);
2828
}
2929

30-
internal static bool IsLocalIpAddress(string hostName)
30+
internal static bool IsLocalIpAddress(string hostName, bool proxyDnsRequests = false)
3131
{
3232
if (IPAddress.TryParse(hostName, out var ipAddress)
3333
&& IsLocalIpAddress(ipAddress))
@@ -52,20 +52,23 @@ internal static bool IsLocalIpAddress(string hostName)
5252
return true;
5353
}
5454

55-
try
55+
if (!proxyDnsRequests)
5656
{
57-
// do reverse DNS lookup even if hostName is an IP address
58-
var hostEntry = Dns.GetHostEntry(hostName);
59-
// if DNS resolved hostname matches local DNS name,
60-
// or if host IP address list contains any local IP address
61-
if (hostEntry.HostName.Equals(localhostEntry.HostName, StringComparison.OrdinalIgnoreCase)
62-
|| hostEntry.AddressList.Any(hostIP => localhostEntry.AddressList.Contains(hostIP)))
57+
try
58+
{
59+
// do reverse DNS lookup even if hostName is an IP address
60+
var hostEntry = Dns.GetHostEntry(hostName);
61+
// if DNS resolved hostname matches local DNS name,
62+
// or if host IP address list contains any local IP address
63+
if (hostEntry.HostName.Equals(localhostEntry.HostName, StringComparison.OrdinalIgnoreCase)
64+
|| hostEntry.AddressList.Any(hostIP => localhostEntry.AddressList.Contains(hostIP)))
65+
{
66+
return true;
67+
}
68+
}
69+
catch (SocketException)
6370
{
64-
return true;
6571
}
66-
}
67-
catch (SocketException)
68-
{
6972
}
7073

7174
return false;

src/Titanium.Web.Proxy/Network/Tcp/TcpConnectionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ internal Task<TcpServerConnection> GetServerConnection(ProxyServer proxyServer,
318318
useUpstreamProxy1 = true;
319319

320320
// check if we need to ByPass
321-
if (externalProxy.BypassLocalhost && NetworkHelper.IsLocalIpAddress(remoteHostName))
321+
if (externalProxy.BypassLocalhost && NetworkHelper.IsLocalIpAddress(remoteHostName, externalProxy.ProxyDnsRequests))
322322
{
323323
useUpstreamProxy1 = false;
324324
}

0 commit comments

Comments
 (0)