使用 Tor 作为代理
我正在尝试使用 Tor-Server 作为 HttpWebRequest 中的代理,我的代码如下所示:
HttpWebRequest request;
HttpWebResponse response;
request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
request.Proxy = new WebProxy("127.0.0.1:9051");
response = (HttpWebResponse)request.GetResponse();
response.Close();
它与“普通”代理完美配合,但使用 Tor 我在调用
GetResponse 时遇到异常() 且状态 = ServerProtocolViolation。该消息是(德语...):Message =“Der Server hat eine Protokollverletzung ausgeführt..Section=ResponseStatusLine”
I'm trying to use Tor-Server as a proxy in HttpWebRequest
, my code looks like this:
HttpWebRequest request;
HttpWebResponse response;
request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
request.Proxy = new WebProxy("127.0.0.1:9051");
response = (HttpWebResponse)request.GetResponse();
response.Close();
it works perfect with "normal" proxies but with Tor I'm getting Exceptions while calling
GetResponse() with Status = ServerProtocolViolation. The message is (in German...):Message = "Der Server hat eine Protokollverletzung ausgeführt.. Section=ResponseStatusLine"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您安装并运行 privoxy 您可以执行
以下操作,这将使您能够使用 tor 发出请求
If you have privoxy installed and running you can do
Which will enable you to make requests using tor
Tor 不是 HTTP 代理。这是一个 SOCKS 代理。您可以使用支持 SOCKS 转发的 HTTP 代理(如 Privoxy)并通过代码连接到该代理。
Tor is not an HTTP proxy. It's a SOCKS proxy. You can use an HTTP proxy that supports forwarding on SOCKS (like Privoxy) and connect to that via code instead.
是的,就像另一位海报所说,需要一个袜子客户端。一些库是 Starksoft Proxy、ProxySocket 和 ComponentSpace Socks代理。 sockscap 是一个拦截和重新路由winsock调用的工具,并且privoxy 是一个本地代理,可以通过袜子传输您的请求。几个不同的解决方案。
Yes like the other poster said, a socks client is needed. Some libraries are Starksoft Proxy, ProxySocket and ComponentSpace Socks Proxy. sockscap is a tool that intercepts and reroutes winsock calls, and privoxy is a local proxy that can tunnel your requests over socks. A couple different solutions.
使用库“SocksWebProxy”。您可以将它与 WebClient 和 WebClient 一起使用。 WebRequest(只需将新的 SocksWebProxy 分配给 *.Proxy 属性)。无需 Privoxy 或类似服务将 http 流量转换为 tor。
https://github.com/Ogglas/SocksWebProxy
我还通过启用控件对其进行了一些扩展港口。以下是如何在不启动 Tor Browser Bundle 的情况下让 Tor 在后台运行,并且为了控制 Tor,我们可以使用 Telnet 或通过 Socket 以编程方式发送命令。
配置 Tor 的步骤:
hashedControlPassword 16:3B7DA467B1C0D550602211995AE8D9352BF942AB04110B2552324B2507
。如果您接受密码为“password”,您可以复制上面的字符串。测试通过 Telnet 修改 Tor:
tor.exe -f .\torrc-defaults
telnet localhost 9151
autenticate “your_password_with_hyphens”
”如果一切顺利,您应该会看到“250 OK”。SIGNAL NEWNYM
”,您将获得一条新路由,即新的 IP。如果一切顺利,您应该会看到“250 OK”。setevents circ
”(电路事件)以启用控制台输出getinfo Circuit-status
”以查看当前电路Use the library "SocksWebProxy". You can use it with WebClient & WebRequest (Just assign a new SocksWebProxy to the *.Proxy attribute). No Need for Privoxy or similar service to translate http traffic to tor.
https://github.com/Ogglas/SocksWebProxy
I made some extensions to it as well by enabling the control port. Here is how you could have Tor running in the background without Tor Browser Bundle started and to control Tor we can use Telnet or send commands programmatically via Socket.
Steps to configure Tor:
tor.exe --hash-password “your_password_without_hyphens” | more
hashedControlPassword 16:3B7DA467B1C0D550602211995AE8D9352BF942AB04110B2552324B2507
. If you accept your password to be "password" you can copy the string above.Test modifying Tor via Telnet:
tor.exe -f .\torrc-defaults
telnet localhost 9151
autenticate “your_password_with_hyphens”
" If all goes well you should see "250 OK".SIGNAL NEWNYM
" and you will get a new route, ergo new IP. If all goes well you should see "250 OK".setevents circ
" (circuit events) to enable console outputgetinfo circuit-status
" to see current circuits您需要从袜子中“提取”流......
You need "extract" a stream from socks...