Blog

Stratux
European Edition | 4/4/2024

As many may know, I have taken over responsibility for the Stratux traffic alerting system ... Read More

AutoWWW 1.1 Released
11/9/2014 | Comments: 2

AutoWWW 1.1 has just been released for Linux. Windows builds do not exist yet, but ... Read More

Backups done right
8/12/2013

Since this is a Blog, I've decided that I should start using it as such and therefore, ... Read More

More Blog Entries

Tor proxy API

AutoWWW provides an easy way to use the Tor proxy infrastructure.

Tor is a public network of anonymization proxies that anyone can use. AutoWWW can even use different proxies for each tab. This makes it possible for your AutoWWW scripts to browse the internet anonymously.

Notice, however, that tor can slow down your connection significantly, which might trigger browser load timeouts too early. If you use this  module, you might have to adjust these timeouts. Check the browser API documentation to see how to do that.

In order to get the AutoWWW tor module to work, you need to follow these steps:

  1. Install tor. For Linux users, it is recommended, but not required, to install tor in you $PATH
    The install location is not important.
    Many Linux distributions provide tor packages in the repository which can be used. Windows users have to download tor from https://www.torproject.org/download/download.html.en and extract it (simply use the Browser-bundle).
  2. You need to tell AutoWWW where it can find tor.
    For Linux users: If tor is installed in you $PATH, you don't need to do anything. If not, you need to call the set_tor_executable function.
    For Windows users: Extract the downloaded tor browser bundle. to a path of your desire. The tor-executable can be found in the installation directory as "Tor Browser/App/tor.exe". You need to pass this path to the set_tor_executable function.

After tor is installed you can use it by writing import tor in your script window. This will make the following functions visible:

tor.set_tor_executable(path)

sets the path to the tor executable that should be run. By default, the PATH environment variable will be checked.

tor.set_tor_data_path(path)

initializes the tor instance manager. the path should be any location on your file system that
tor may use to store its temporary files. If this directory doesn't exist, it will be created and kept.
Feel free to remove this directory if you don't need it any more. Keeping it will speed up tor initialization
significantly. But when you don't need tor any more, you can of course delete it.

tor.create_tor_tab()

Creates a new browser tab that will be proxied by a new tor instance. Tabs created with this function should always be deleted with tor.remove_tor_tab(). Otherwise, tor instances might leak.
Returns: the tab ID.

tor.remove_tor_tab(tab)

Removes a tab that was created by create_tor_tab() and closes its tor-instance.

tor.close_all_tors()

Closes all running tor-instances. It does not close the tabs created by create_tor_tab, but only the proxy instances. I.e., all tabs created with create_tor_tab() will not be able to load pages any more because the proxy is unavailable.

tor.start_instance()

Starts a tor-instance and returns the port on which it is running. This might be given to browser.set_proxy().

tor.stop_instance(port)

stops the tor instance running on the given port

tor.set_port_range(starting_port)

sets the starting port on which proxies should be created. defaults to 8000, 8001, 8002,...

 

Example tor script

The script below will open five tabs, each tab with its own tor instance. It will then show you the current proxy-IP in all tabs.
NOTE: especially the first time tor runs on a specific port, startup can take a very long time. That's why the timeout is set so high.

import tor

tor.set_tor_executable('C:/Users/ben/Downloads/Tor Browser/App/tor.exe')
tabs = []
browser.set_load_timeout(1000)

for i in range(5):
  t = tor.create_tor_tab()
  browser.select_page(t)
  browser.load_page('http://abatzill.de/get_ip.php') # NOTE: takes a while the first time
  tabs.append(t)
  time.sleep(1)

for i in tabs:
  tor.remove_tor_tab(i)