Giter VIP home page Giter VIP logo

toripy's Introduction

Toripy

Lightweight python interface to easily make HTTP(s) requests over the Tor network

Install

pip install toripy

Usage

The 3 following code examples cover this 3 different scenarios

  • Using Toripy minimal config to run a Tor process and make a request over the Tor network.
  • Using Toripy custom config to run a Tor process and make a request over the Tor network using an specific exit node.
  • Using Toripy custom config to run a Tor process, launch Firefox with selenium using this Tor process as a proxy, and automate actions while connected to this proxy.

Minimal config

from toripy import Toripy

LOCAL_TOR = '/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/tor'

with Toripy(tor_cmd=LOCAL_TOR) as toripy:
    ip_adress = toripy.get('http://www.icanhazip.com').text
    print('This should not be your IP adress:')
    print(ip_adress)

Custom Config

In this example we choose '{ru}' as the exit node. This means that our exit node will be located in Russia (meaning also that our disclosed IP will be from Russia). You can also choose a group of exit nodes, or one exit node IP in particular, so your proccess uses always the same exit node.

from toripy import Toripy

LOCAL_TOR = '/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/tor'
SOCKS_HOST = "127.0.0.1"
SOCKS_PORT = 7000

tor_config = {
    'SocksPort': str(SOCKS_PORT),
    'ControlPort': str(9051),
    'ExitNodes': '{ru}',
    'GeoIPFile': r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip',
    'GeoIPv6File': r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip6'
}

with Toripy(tor_cmd=LOCAL_TOR, verbose=True, tor_config=tor_config) as toripy:
    ip_adress = toripy.get('http://www.icanhazip.com').text
    print('This should be a russian ip adress:')
    print(ip_adress)

Custom Config + Selenium w/Firefox

To run this example make sure you have Firefox, Geckodriver and Selenium installed.

import time
from toripy import Toripy
from selenium import webdriver

LOCAL_TOR = '/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/tor'
SOCKS_HOST = "127.0.0.1"
SOCKS_PORT = 7000

tor_config = {
    'SocksPort': str(SOCKS_PORT),
    'ControlPort': str(9051),
    'ExitNodes': '{ru}',
    'GeoIPFile': r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip',
    'GeoIPv6File': r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip6'
}

with Toripy(tor_cmd=LOCAL_TOR, verbose=True, tor_config=tor_config, use_default_proxy=True):
    fp = webdriver.FirefoxProfile()
    fp.set_preference("network.proxy.type", 1)
    fp.set_preference("network.proxy.socks",SOCKS_HOST)
    fp.set_preference("network.proxy.socks_port",int(SOCKS_PORT))
    fp.update_preferences()
    driver = webdriver.Firefox(firefox_profile=fp)
    driver.get("https://www.infobyip.com/")

toripy's People

Contributors

nikoferro avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.