How to install nonProxyHosts for SOCKS proxy

I want to set nonProxyHosts list for SOCKS5 proxy, i.e. A list of host names to which to use a direct connection.

As described by oracle docs , there are options called http.nonProxyHosts and ftp.nonProxyHosts for setting proxy exceptions for HTTP and FTP, but there is no specific setting for SOCKS proxies.

I tried http.nonProxyHosts , but this does not affect SOCKS connections.

SOCKS proxy is configured through:

 System.setProperty("socksProxyHost", "192.168.10.10"); System.setProperty("socksProxyPort", "3128"); 

But this leads to the fact that even DB connections to localhost use SOCKS proxies, which is unacceptable.

How is it supposed to be used? How can I exclude certain nodes from proxied compounds?

+6
source share
1 answer

The documentation for Java network properties says the following:

As soon as the SOCKS proxy server is specified in this way, attempts to connect all will be made through the proxy.

(emphasis added)

There are no settings for installing hosts without a proxy through sock properties.


You may be able to use the Proxy and / or ProxySelector , but:

  • ProxySelector is only applicable if your application uses URLConnection to establish connections.

  • Proxy applicable for arbitrary sockets ... but only if you can provide a Proxy object as a parameter for the corresponding calls to the Socket constructor. (And you will need the logic to deliver the various Proxy objects depending on what your code is trying to connect to.)


There's an outstanding RFE for this: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=5001942

The ticket offers another workaround. Apparently, if the java.net.useSystemProxies property is true , then (on some platforms) the proxy server selector will respect the exclusion of hosts specified in the corresponding proxy server settings by default.

+6
source

Source: https://habr.com/ru/post/974211/


All Articles