在 C# 中使用 Tor 下载文件 [英] Download file using Tor in C#

查看:52
本文介绍了在 C# 中使用 Tor 下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Tor 下载文件.我发现的大多数解决方案都需要安装并运行其他软件(例如 privoxy),但我不想让其他软件一直运行,即使我不使用我的程序.

I want to download a file using Tor. Most solutions I found require that additional software (e.g. privoxy) is installed and running, but I don't want to have an additional software running all the time even when I don't use my program.

所以我尝试了 Tor.NET 库,但我无法使用 Tor.这个例子不应该返回我的 IP 地址,但它确实:

So I tried the Tor.NET library, but I can't get it using Tor. This example shouldn't return my IP-address, but it does:

ClientCreateParams createParams = new ClientCreateParams(@"D:\tor.exe", 9051);
Client client = Client.Create(createParams);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.icanhazip.com/");
request.Proxy = client.Proxy.WebProxy;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    var reader = new StreamReader(response.GetResponseStream());
    Console.WriteLine(reader.ReadToEnd());
}

Console.WriteLine("Press enter to exit...");
Console.ReadLine();

已经有很多关于此的评论,但不幸的是该库的作者不再活跃.

There are already multiple comments about this but unfortunally the author of the library isn't active anymore.

也许您知道我做错了什么(是否需要更多配置?)或者对使用 tor 下载文件的替代方法有想法.

Maybe you know what I'm doing wrong (is more configuration neccessary?) or have an idea for an alternative way to download a file using tor.

推荐答案

您按照 Tor 项目手册,命令行 HTTPTunnelPort,您找到 此处:首先您必须使用

You follow the Tor project manual, command line HTTPTunnelPort, that you find here: first you must start a HTTP tunnel with

Tor.exe --HTTPTunnelPort 4711

它在 127.0.0.1:4711 为您提供 HTTP 隧道(另请参见 此处).现在您可以连接到此代理:

It supplies you with a HTTP tunnel at 127.0.0.1:4711 (see also here). Now you can connect to this proxy:

WebProxy oWebProxy = new WebProxy (IPAddress.Loopback.ToString (), 4711);
WebClient oWebClient = new WebClient ();
oWebClient.Proxy = oWebProxy;
oWebClient.DownloadFile ("http://myUri", "myFilename");

使用 Tor.exe 时请注意以下事项:

Please heed the following in using Tor.exe:

  • 如果端口已被使用,Tor.exe 将无法提供代理.它甚至不一定会通知您有关此故障的信息.
  • 确保没有人欺骗您的程序 Tor.exe,以便 Tor 为您提供此代理.因此,Tor.exe 应该位于文件系统中的安全位置.
  • 了解有关使用 Tor 的其他预防措施.
  • If the port is already in use Tor.exe will not be able to supply a proxy. It does not even necessarily inform you about this failure.
  • Make sure that nobody spoofs your program Tor.exe so that it is Tor that supplies you with this proxy. Hence, Tor.exe should be at a secure place in your file system.
  • Inform yourself about other precautions with respect to using Tor.

至少,您可能需要检查您的代理与本地互联网连接的 IP 地址是否不同.

At least, you might want to check that your proxy has a different IP adress from your local internet connection.

这篇关于在 C# 中使用 Tor 下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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