Skip to main content

A python module for Chaining of Proxies.

Project description

proxychains

This is a pretty heavily modified pyChainedProxy, which is a fork of socksipy, and is somehow related to PySocksipyChain.

I'm not entirely sure about the hierarchy of those projects, so i'm going to mention everyone, and use a GPL license.

Copyright (c) 2020 Aman Kumar. All rights reserved.
Copyright 2011 Bjarni R. Einarsson. All rights reserved.
Copyright 2006 Dan-Haim. All rights reserved.

Changes include:

  • Dropped python 2 support
  • Code readability changes
  • https/ssl connect chaining support

https://pypi.org/project/proxychains/

Proxy support

  • SOCKS4
  • SOCKS5
  • HTTP: Cannot be anywhere except the end of the chain, or proxy anything except http requests, unless the proxy supports the connect method, in which case the library will use HTTP_CONNECT
  • HTTPS: Same as above
  • HTTP_CONNECT
  • HTTPS_CONNECT
  • SSL: Unsure about the usage.
  • DEFAULT: Use the global chain. Unsure about the usage.
  • TOR: Should be completely identical to SOCKS5

Install

pip install proxychains

Example

Note that the example isn't complete. Check the source code for other methods or use the documentation of the other projects.

import requests
from requests.structures import CaseInsensitiveDict
from http.client import HTTPConnection
from urllib.parse import urlparse
import proxychains as socks
# socks.ENABLE_DEBUG = True

# https://stackoverflow.com/questions/46446904/encoding-an-http-request-in-python/46448489
class TunneledHTTPConnection(HTTPConnection):
    def __init__(self, transport, *args, **kwargs):
        self.transport = transport
        HTTPConnection.__init__(self, *args, **kwargs)

    def connect(self):
        self.transport.connect((self.host, self.port))
        self.sock = self.transport

class TunneledHTTPAdapter(requests.adapters.BaseAdapter):
    def __init__(self, transport):
        self.transport = transport

    def close(self):
        pass

    def send(self, request, **kwargs):
        scheme, location, path, params, query, anchor = urlparse(request.url)
        if ':' in location:
            host, port = location.split(':')
            port = int(port)
        else:
            host = location
            port = 80

        connection = TunneledHTTPConnection(self.transport, host, port)
        connection.request(method=request.method,
                           url=request.url,
                           body=request.body,
                           headers=request.headers)
        r = connection.getresponse()
        resp = requests.Response()
        resp.status_code = r.status
        resp.headers = CaseInsensitiveDict(r.headers)
        resp.raw = r
        resp.reason = r.reason
        resp.url = request.url
        resp.request = request
        resp.connection = connection
        resp.encoding = requests.utils.get_encoding_from_headers(r.headers)
        requests.cookies.extract_cookies_to_jar(resp.cookies, request, r)
        return resp

if __name__ == '__main__':
    with requests.Session() as session:
        sock = socks.socksocket()
        sock.addproxy(socks.parseproxy("httpcs://127.0.0.1:8080"))  # this will use HTTPS_CONNECT
        sock.addproxy(socks.Proxy(
            socks.ProxyType.SOCKS5,  # the proxy type
            "127.0.0.1",  # host
            8081,  # port
            remote_dns=False,  # whether we should resolve the next host locally, or let this host handle it. Default: False
            username="login",  # proxy login
            password="hunter2"  # proxy password
        ))
        # socks.usesystemdefaults()  # this will use enviroment variables to set proxy. there is no support for chains
        session.mount("http://", TunneledHTTPAdapter(sock))
        session.mount("https://", TunneledHTTPAdapter(sock))
        print(session.get("https://httpbin.org/ip").json()["origin"])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

proxychains-1.0.1.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

proxychains-1.0.1-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file proxychains-1.0.1.tar.gz.

File metadata

  • Download URL: proxychains-1.0.1.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4

File hashes

Hashes for proxychains-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0eddd4c321f37508b4299581ecaa0dde02b31b388f13300aff5be426c289f848
MD5 5cec478227aedc8bf886e4f3107890c0
BLAKE2b-256 81ae62365fcfc99750723406d2445d27a675a17993a7e907ea0ae36db8575666

See more details on using hashes here.

File details

Details for the file proxychains-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: proxychains-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4

File hashes

Hashes for proxychains-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e861b2854d76d0383bae79728ba8d7d81e94d08db776510b6fc4c017f37c8d7
MD5 17cdbc04eb2f34206c1adfa44edafbd1
BLAKE2b-256 aa51da41fea87803a3df972654aa597868248436b338242dd29c05263df01d7c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page