C# combining GeckoFX + Tor.NET libraries

1k views Asked by At

I am trying to combine GeckoFx library and Tor.NET library.

In my code I do all preparing to use tor network,

ClientCreateParams createParameters = new ClientCreateParams();
createParameters.ConfigurationFile = ConfigurationManager.AppSettings["torConfigurationFile"];
createParameters.ControlPassword = ConfigurationManager.AppSettings["torControlPassword"];
createParameters.ControlPort = Convert.ToInt32(ConfigurationManager.AppSettings["torControlPort"]);
createParameters.DefaultConfigurationFile = ConfigurationManager.AppSettings["torDefaultConfigurationFile"];
createParameters.Path = Path.Combine(root, ConfigurationManager.AppSettings["torPath"]);

createParameters.SetConfig(ConfigurationNames.AvoidDiskWrites, true);
createParameters.SetConfig(ConfigurationNames.GeoIPFile, Path.Combine(root, @"Tor\Data\Tor\geoip"));
createParameters.SetConfig(ConfigurationNames.GeoIPv6File, Path.Combine(root, @"Tor\Data\Tor\geoip6"));

client = Client.Create(createParameters);


  <appSettings>
    <add key="torConfigurationFile" value=""/>
    <add key="torControlPassword" value=""/>
    <add key="torControlPort" value="9051"/>
    <add key="torDefaultConfigurationFile" value=""/>
    <add key="torPath" value="Tor\Tor\tor.exe"/>
 </appSettings>

WebBrowser1 is a simple browser and it works with Tor settings. But browser is GeckoFx and it doesn't work.

webBrowser1.Navigate("https://duckduckgo.com/?q=my+ip&t=h_&ia=answer");
browser.Navigate("https://duckduckgo.com/?q=my+ip&t=h_&ia=answer");

this As you see ip should be as on left control. You can download and test full project from here. It is WinForms project just run "Gecko" project from solution. Any idea how to set GeckoFx use Tor network? Or maybe I need somehow setup GeckoFx to use proxy?

        //GeckoPreferences.User["network.proxy.type"] = 1;
        //GeckoPreferences.User["network.proxy.socks"] = "127.0.0.1";
        //GeckoPreferences.User["network.proxy.socks_port"] = 9150;
        //GeckoPreferences.User["network.proxy.socks_version"] = 5;
        //GeckoPreferences.User["network.proxy.socks_remote_dns"] = true;

VisualStudio 2015. Thank you.

2

There are 2 answers

0
drew010 On BEST ANSWER

Have you set any of the Firefox Preferences in your code before initializing the browser?

Try:

GeckoPreferences.Default["network.proxy.type"] = 1;
GeckoPreferences.Default["network.proxy.socks = "127.0.0.1"
GeckoPreferences.Default["network.proxy.socks_port"] = 9050
GeckoPreferences.Default["network.proxy.socks_remote_dns"] = 1
GeckoPreferences.Default["network.proxy.socks_version"] = 5

The network.proxy.type value of 1 is equivalent to "Manual Proxy Configuration" settings.

The following settings configure the SOCKS proxy settings to use Tor at 127.0.0.1:9050 with DNS resolution over SOCKS (Tor).

It seems like this should properly configure GeckoFX to use Tor.

0
Yury Glushkov On

Tor network is not designed for immediate HTTP proxy communications. Instead, TOR.NET implements web proxy, that listens for connections on port 8182 by default.

Also you can assign another port with

client.Proxy.Port = 8042;

Keep in mind, that if you changes proxy port, TOR.NET shutdowns existing http listener, and creates a new one.

So, you need to configure Gecko, to use this web proxy on localhost.