Question

trying to create web request using Tor. getting this error - "Unable to connect to the remote server". Tor default proxy - 8118. i have goggled for it found solution for it using Tor as Proxy but it didn't worked for me.

Code-

Process p = new Process();
p.StartInfo = new ProcessStartInfo(@"C:\Users\king\Downloads\Tor Browser\App\tor.exe", "ControlPort 9151 CircuitBuildTimeout 10");
p.Start();
Thread.Sleep(5000);
Regex regex = new Regex("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}", RegexOptions.Multiline);

do
{       

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://whatismyipaddress.com/");
    request.Headers.Add("Cache-Control", "max-age=0");
    request.Proxy = new WebProxy("127.0.0.1:8118");
    request.KeepAlive = false;

    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {

        using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")))
        {
            string contenu = reader.ReadToEnd();
            Console.WriteLine(regex.Match(contenu).Groups[0].Value);
        }
    }
    Console.Write("en attente : continuez ?");
    string line = Console.ReadLine();
    if (line != "y")
        break;
}
while (true);

p.Kill();
Console.ReadLine();

any idea what doing wrong in above code. thank's

Was it helpful?

Solution 2

Tor default proxy port is 8118. you have to first download privoxy here

To chain Privoxy and Tor, both running on the same system, you would use something like:

    forward-socks5 / 127.0.0.1:9050 

change its config to work with tor by uncommenting the above line

c# does not use sock proxies so that we have to run Tor and Provoxy at same. now you can send every web request using tor.

OTHER TIPS

Just download the Privoxy here

the reason to run tor through privoxy is because c# does not work with socks proxies. and tor is a socks proxy, so it needs to be ran through a html proxy that runs through tor

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top