Skip to main content

SocketSwap is a python package that allows to proxy any third-party libraries traffic through a local TCP Proxy

Project description

SocketSwap

SocketSwap is a tool that allows to proxy any third-party libraries traffic through a TCP SOCKS5 Proxy.

Some Python libaries support proxing out of the box like requests. For all other libaries especially ones not natively written in python, you can use SocketSwap to redirect traffic via a proxy.

Usage:

There are two ways to use SwapSock.

- Via a Context Manager that starts the proxy in a daemon process
- Directly as a blocking script

Context Manager

import socket
from SocketSwap import ProxySwapContext


def socket_factory():
    target_host = "localhost"
    target_port = 5432
    remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    remote_socket.connect((target_host, target_port))
    return remote_socket

def main():
    
    with ProxySwapContext(socket_factory, "127.0.0.1", 2222):
        # do something you want to proxy
        # connect to 127.0.0.1:2222

The ProxySwapContext takes essentially 3 mandatory arguments.

Logging and Debugging

from SocketSwap import ProxySwapContext

# debug level logging
import logging
socket_swap_logger = logging.getLogger("SocketSwap")
socket_swap_logger.addHandler(logging.StreamHandler())
socket_swap_logger.setLevel(logging.DEBUG)

By default logging is not enabled. You can do so by assigning a handler to the "SocketSwap" logger and choosing a level.

Credits:

The TCP Proxy part is a slim modified version of https://github.com/ickerwx/tcpproxy.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SocketSwap-0.1.10-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file SocketSwap-0.1.10-py2.py3-none-any.whl.

File metadata

  • Download URL: SocketSwap-0.1.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for SocketSwap-0.1.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0d8296d4a0198c3dab32082e6e0a087bfd949be77b453d434dbbba6bf7a74c8e
MD5 f026f0a4742b158cd2f6de23a0b1bec3
BLAKE2b-256 81dee50a3967c6ea4da794a1d74c44068d9ba7991273c8663f4eb472668f4b12

See more details on using hashes here.

Supported by

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