如何通过代理(Tor)浏览时阻止Java预解析主机? [英] How to stop Java from preresolving my host while browsing via Proxy ( Tor )?

查看:84
本文介绍了如何通过代理(Tor)浏览时阻止Java预解析主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个Java应用程序,该应用程序使用在localhost上运行的tor代理来获取显示请求者ip的脚本.

I am currently developing a java application that is using a tor proxy running on localhost to fetch a script that is displaying the requesters ip.

我希望这项工作主要由Tor代理完成,以便它可以在其最自然"的状态下工作.我当前的代码与此类似:

I would like the work to be done mostly by the tor proxy, so that it works in its most "natural" state. My current Code looks similar to this:

SocketAddress TorProxyAddress = new InetSocketAddress("127.0.0.1", 9050);
Proxy TorProxy = new Proxy(Proxy.Type.SOCKS, TorProxyAddress);
URL url = new URL("https://myhost.com/ip2.php");
URLConnection conn = url.openConnection(TorProxy);
// ... reading the input stream etc

我现在遇到的问题是来自tor代理控制台的以下警告消息:

The problem I am now encountering is the following warn message from the tor proxy console:

[warn] Your application (using socks5 to port 443) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead. For more information, please see https://wiki.torproject.org/TheOnionRouter/TorFAQ#SOCKSAndDNS.'

对我来说,Java似乎在解决myhost.com的IP地址而我却不想这样做.如前所述,我需要在可能完美的环境中运行tor代理.

For me, it looks like Java is resolving the ip adress of myhost.com without me wanting it to do so. As already mentioned, I need to run the tor proxy in a possibly perfect environment.

有什么方法可以防止java预解析主机并将整个URL传递给tor代理吗?

Is there any way to prevent java from pre-resolving the host and just passing the whole URL to the tor proxy?

非常感谢您的每一个回答!

Thank you very much for every answer!

推荐答案

我自己找到了一个简单的答案,就像阅读 InetSocketAddress

I found a simple answer myself, it is as easy as reading the API for InetSocketAddress

要阻止Java预解析主机,只需使用:

To stop Java from preresolving the Host, just use:

InetSocketAddress unresolvedAdr = InetSocketAddress.createUnresolved(host, port);

如果您有兴趣,这是我的完整解决方案(在我特殊的情况下,使用ssl-stuff):

If you are interested, here is my full solution (in my special case with ssl-stuff):

TorProxyAddress = new InetSocketAddress("127.0.0.1", 9050);
Proxy TorProxy = new Proxy(Proxy.Type.SOCKS, TorProxyAddress);
Socket underlying = new Socket(TorProxy);

InetSocketAddress unresolvedAdr = InetSocketAddress.createUnresolved(host, port);
underlying.connect(unresolvedAdr);

SSLSocket socket = (SSLSocket) SockFactory.createSocket(underlying, "127.0.0.1", 9050, true);
// ... Read from / write to Socket

这篇关于如何通过代理(Tor)浏览时阻止Java预解析主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆