You can use the library "SocksWebProxy". It can be used with WebClient & WebRequest (Just assign a new SocksWebProxy to the *.Proxy attribute). No Need for Privoxy or similar service to translate http traffic to tor.
I made some extensions to it as well by enabling the control port. Here is how you could have Tor running in the background without Tor Browser Bundle started and to control Tor we can use Telnet or send commands programmatically via Socket.
Socket server = null;
//Authenticate using control password
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9151);
server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
server.Send(Encoding.ASCII.GetBytes("AUTHENTICATE \"your_password\"" + Environment.NewLine));
byte data = new byte;
int receivedDataLength = server.Receive(data);
string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
//Request a new Identity
server.Send(Encoding.ASCII.GetBytes("SIGNAL NEWNYM" + Environment.NewLine));
data = new byte;
receivedDataLength = server.Receive(data);
stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength);
Console.WriteLine("Unable to signal new user to server.");
Console.WriteLine("SIGNAL NEWNYM sent successfully");
Steps to configure Tor:
- Copy torrc-defaults into the directory in which tor.exe is. Default directory if you are using Tor browser is: "~\Tor Browser\Browser\TorBrowser\Data\Tor"
- Open a cmd prompt window
- chdir to the directory where tor.exe is. Default directory if you are using Tor browser is: "~\Tor Browser\Browser\TorBrowser\Tor\"
- Generate a password for Tor control port access.
tor.exe --hash-password “your_password_without_hyphens” | more
- Add your password password hash to torrc-defaults under ControlPort 9151. It should look something like this:
hashedControlPassword 16:3B7DA467B1C0D550602211995AE8D9352BF942AB04110B2552324B2507. If you accept your password to be "password" you can copy the string above.
- You can now access Tor control via Telnet once it is started. Now the code can run, just edit the path to where your Tor files are located in the program.
Test modifying Tor via Telnet:
- Start tor with the following command:
tor.exe -f .\torrc-defaults
- Open up another cmd prompt and type:
telnet localhost 9151
- If all goes well you should see a completely black screen. Type "
autenticate “your_password_with_hyphens”" If all goes well you should see "250 OK".
- Type "
SIGNAL NEWNYM" and you will get a new route, ergo new IP. If all goes well you should see "250 OK".
- Type "
setevents circ" (circuit events) to enable console output
- Type "
getinfo circuit-status" to see current circuits