@@ -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 ;
0 commit comments