How to Run Multiple Tor Processes at Once with Different Exit Ips

How to run multiple Tor processes at once with different exit IPs?

Create four torrc files, say /etc/tor/torrc.1 to .4.

In each file, edit the lines:

SocksPort 9050
ControlPort 9051
DataDirectory /var/lib/tor

to use different resources for each torrc file, e.g. for for torrc.1:

SocksPort 9060
ControlPort 9061
DataDirectory /var/lib/tor1

for torrc.2,

SocksPort 9062
ControlPort 9063
DataDirectory /var/lib/tor2

and so on.

A configuration file containing only the above lines will work: you can delete every other line from the default template if you feel like it.

DataDirectory can also be relative to the current directory where tor is launched, e.g.:

DataDirectory d1

Then start tor like this:

tor -f /etc/tor/torrc.1  
tor -f /etc/tor/torrc.2

and so on for the other two files.

This will create four different Socks5 servers on the four ports. Each one will open a different circuit, which is what you want.

How to run Multiple Tor Browser instances on windows?

Make a copy of your installed Tor directory. (For example copy to Tor Browser2)
Edit the file \Tor Browser2\Browser\TorBrowser\Data\Browser\profile.default\prefs.js
In my example the socks port is 9250, the control port is 9251
user_pref("network.proxy.socks_port", 9250);
user_pref("network.security.ports.banned", "9050,9051,9250,9251");
user_pref("extensions.torlauncher.control_port", 9251);

Here you can see that 2 Tor instances are running.

Different TOR IPs at http/https

It is because something like "TOR keep-alive". It is remember the exit node you access the website from and tries to use it again after exit node change even.
All is needed to fix this is to close the connection. Like the following:

resp1 = sess.get('http://wtfismyip.com/text')
ip1 = resp1.text

change_node()
resp1.connection.close()

resp2 = sess.get('http://wtfismyip.com/text')
ip2 = resp2.text

After that the IPs are different.

Connecting to Many TOR Exit Nodes

This article explains it in depth with examples...

http://blog.databigbang.com/distributed-scraping-with-multiple-tor-circuits/

How i can get new ip from tor every requests in threads?

If you want different IPs for each connection, you can also use Stream Isolation over SOCKS by specifying a different proxy username:password combination for each connection.

With this method, you only need one Tor instance and each requests client can use a different stream with a different exit node.

In order to set this up, add unique proxy credentials for each requests.session object like so: socks5h://username:password@localhost:9050

import random
from multiprocessing import Pool
import requests

def check_ip():
session = requests.session()
creds = str(random.randint(10000,0x7fffffff)) + ":" + "foobar"
session.proxies = {'http': 'socks5h://{}@localhost:9050'.format(creds), 'https': 'socks5h://{}@localhost:9050'.format(creds)}
r = session.get('http://httpbin.org/ip')
print(r.text)


with Pool(processes=8) as pool:
for _ in range(9):
pool.apply_async(check_ip)
pool.close()
pool.join()

Tor Browser isolates streams on a per-domain basis by setting the credentials to firstpartydomain:randompassword, where randompassword is a random nonce for each unique first party domain.

If you're crawling the same site and you want random IP's, then use a random username:password combination for each session. If you are crawling random domains and want to use the same circuit for requests to a domain, use Tor Browser's method of domain:randompassword for credentials.



Related Topics



Leave a reply



Submit