Skip to main content

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"])

Release files for proxychains 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for proxychains 1.0.1
File Size Uploaded
proxychains-1.0.1.tar.gz 24.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for proxychains 1.0.1
File Interpreter ABI Platform
proxychains-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size:47.4 kB

Release files / proxychains-1.0.1.tar.gz

Download URL proxychains-1.0.1.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0eddd4c321f37508b4299581ecaa0dde02b31b388f13300aff5be426c289f848
BLAKE2b-256 checksum
How to use checksums
81ae62365fcfc99750723406d2445d27a675a17993a7e907ea0ae36db8575666
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4

Release files / proxychains-1.0.1-py3-none-any.whl

Download URL proxychains-1.0.1-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e861b2854d76d0383bae79728ba8d7d81e94d08db776510b6fc4c017f37c8d7
BLAKE2b-256 checksum
How to use checksums
aa51da41fea87803a3df972654aa597868248436b338242dd29c05263df01d7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page