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");
//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.
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.
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.
来源:https://stackoverflow.com/questions/41377272/c-sharp-combining-geckofx-tor-net-libraries