Skip to content

Use Tor for your C# HTTP clients. Tor + Privoxy = ❤️

License

Notifications You must be signed in to change notification settings

UsiPusichka/TorSharp

 
 

Repository files navigation

TorSharp

Use Tor for your C# HTTP clients. Tor + Privoxy = ❤️

All you need is client code that can use a simple HTTP proxy.

Build status

Details

  • Uses Privoxy to redirect HTTP proxy traffic to Tor.
  • Uses virtual desktops to manage Tor and Privoxy processes.
  • Optionally downloads the latest version of Tor and Privoxy.

Install

Install-Package Knapcode.TorSharp

NuGet version

Example

// configure
var settings = new TorSharpSettings
{
    ZippedToolsDirectory = Path.Combine(Path.GetTempPath(), "TorZipped"),
    ExtractedToolsDirectory = Path.Combine(Path.GetTempPath(), "TorExtracted"),
    PrivoxyPort = 1337,
    TorSocksPort = 1338,
    TorControlPort = 1339,
    TorControlPassword = "foobar"
};

// download tools
await new TorSharpToolFetcher(settings, new HttpClient()).FetchAsync();

// execute
var proxy = new TorSharpProxy(settings);
var handler = new HttpClientHandler
{
    Proxy = new WebProxy(new Uri("http://localhost:" + settings.PrivoxyPort))
};
var httpClient = new HttpClient(handler);
await proxy.ConfigureAndStartAsync();
Console.WriteLine(await httpClient.GetStringAsync("http://api.ipify.org"));
await proxy.GetNewIdentityAsync();
Console.WriteLine(await httpClient.GetStringAsync("http://api.ipify.org"));
proxy.Stop();

About

Use Tor for your C# HTTP clients. Tor + Privoxy = ❤️

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%