PHP 8.3.30
Preview: sockshandler.py Size: 2.84 KB
//proc/self/root/lib/python3.6/site-packages/sockshandler.py

#!/usr/bin/env python
"""
SocksiPy + urllib2 handler

version: 0.3
author: e<e@tr0ll.in>

This module provides a Handler which you can use with urllib2 to allow it to tunnel your connection through a socks.sockssocket socket, with out monkey patching the original socket...
"""
import ssl

try:
    import urllib2
    import httplib
except ImportError: # Python 3
    import urllib.request as urllib2
    import http.client as httplib

import socks # $ pip install PySocks

def merge_dict(a, b):
    d = a.copy()
    d.update(b)
    return d

class SocksiPyConnection(httplib.HTTPConnection):
    def __init__(self, proxytype, proxyaddr, proxyport=None, rdns=True, username=None, password=None, *args, **kwargs):
        self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
        httplib.HTTPConnection.__init__(self, *args, **kwargs)

    def connect(self):
        self.sock = socks.socksocket()
        self.sock.setproxy(*self.proxyargs)
        if type(self.timeout) in (int, float):
            self.sock.settimeout(self.timeout)
        self.sock.connect((self.host, self.port))

class SocksiPyConnectionS(httplib.HTTPSConnection):
    def __init__(self, proxytype, proxyaddr, proxyport=None, rdns=True, username=None, password=None, *args, **kwargs):
        self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
        httplib.HTTPSConnection.__init__(self, *args, **kwargs)

    def connect(self):
        sock = socks.socksocket()
        sock.setproxy(*self.proxyargs)
        if type(self.timeout) in (int, float):
            sock.settimeout(self.timeout)
        sock.connect((self.host, self.port))
        self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)

class SocksiPyHandler(urllib2.HTTPHandler, urllib2.HTTPSHandler):
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kw = kwargs
        urllib2.HTTPHandler.__init__(self)

    def http_open(self, req):
        def build(host, port=None, timeout=0, **kwargs):
            kw = merge_dict(self.kw, kwargs)
            conn = SocksiPyConnection(*self.args, host=host, port=port, timeout=timeout, **kw)
            return conn
        return self.do_open(build, req)

    def https_open(self, req):
        def build(host, port=None, timeout=0, **kwargs):
            kw = merge_dict(self.kw, kwargs)
            conn = SocksiPyConnectionS(*self.args, host=host, port=port, timeout=timeout, **kw)
            return conn
        return self.do_open(build, req)

if __name__ == "__main__":
    import sys
    try:
        port = int(sys.argv[1])
    except (ValueError, IndexError):
        port = 9050
    opener = urllib2.build_opener(SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, "localhost", port))
    print("HTTP: " + opener.open("http://httpbin.org/ip").read().decode())
    print("HTTPS: " + opener.open("https://httpbin.org/ip").read().decode())

Directory Contents

Dirs: 47 × Files: 14

Name Size Perms Modified Actions
chardet DIR
- drwxr-xr-x 2025-04-30 10:03:38
Edit Download
- drwxr-xr-x 2025-04-30 10:03:38
Edit Download
dateutil DIR
- drwxr-xr-x 2025-04-30 10:03:22
Edit Download
- drwxr-xr-x 2025-04-30 10:03:11
Edit Download
dnf DIR
- drwxr-xr-x 2025-04-30 10:19:18
Edit Download
- drwxr-xr-x 2025-09-23 07:51:47
Edit Download
- drwxr-xr-x 2025-04-30 10:03:51
Edit Download
dns DIR
- drwxr-xr-x 2025-04-30 10:55:23
Edit Download
- drwxr-xr-x 2025-04-30 10:55:23
Edit Download
firewall DIR
- drwxr-xr-x 2025-04-30 10:19:13
Edit Download
html2text DIR
- drwxr-xr-x 2025-04-30 10:55:17
Edit Download
- drwxr-xr-x 2025-04-30 10:55:17
Edit Download
idna DIR
- drwxr-xr-x 2025-04-30 10:18:07
Edit Download
- drwxr-xr-x 2025-04-30 10:18:07
Edit Download
iotop DIR
- drwxr-xr-x 2025-05-01 12:22:46
Edit Download
isc DIR
- drwxr-xr-x 2026-04-16 16:59:13
Edit Download
nftables DIR
- drwxr-xr-x 2025-04-30 10:19:12
Edit Download
OpenSSL DIR
- drwxr-xr-x 2025-04-30 10:03:41
Edit Download
pip DIR
- drwxr-xr-x 2025-04-30 10:02:06
Edit Download
- drwxr-xr-x 2025-04-30 10:02:06
Edit Download
- drwxr-xr-x 2025-07-17 07:09:06
Edit Download
ply DIR
- drwxr-xr-x 2025-04-30 10:03:39
Edit Download
- drwxr-xr-x 2025-04-30 10:03:39
Edit Download
procfs DIR
- drwxr-xr-x 2025-04-30 10:03:22
Edit Download
pycparser DIR
- drwxr-xr-x 2025-04-30 10:03:39
Edit Download
- drwxr-xr-x 2025-04-30 10:03:39
Edit Download
- drwxr-xr-x 2025-04-30 10:03:41
Edit Download
- drwxr-xr-x 2025-04-30 10:03:41
Edit Download
- drwxr-xr-x 2025-04-30 10:03:42
Edit Download
- drwxr-xr-x 2025-04-30 10:03:22
Edit Download
- drwxr-xr-x 2025-04-30 10:03:22
Edit Download
pyudev DIR
- drwxr-xr-x 2025-04-30 10:03:22
Edit Download
- drwxr-xr-x 2025-04-30 10:03:22
Edit Download
requests DIR
- drwxr-xr-x 2025-08-06 23:18:17
Edit Download
- drwxr-xr-x 2025-08-06 23:18:17
Edit Download
rhn DIR
- drwxr-xr-x 2025-05-29 13:47:19
Edit Download
- drwxr-xr-x 2025-07-17 07:09:06
Edit Download
- drwxr-xr-x 2025-07-17 07:09:06
Edit Download
- drwxr-xr-x 2025-04-30 10:02:53
Edit Download
slip DIR
- drwxr-xr-x 2025-04-30 10:03:38
Edit Download
- drwxr-xr-x 2025-07-17 07:09:06
Edit Download
- drwxr-xr-x 2025-07-17 07:09:06
Edit Download
tuned DIR
- drwxr-xr-x 2025-04-30 10:19:29
Edit Download
- drwxr-xr-x 2025-07-18 06:30:11
Edit Download
urllib3 DIR
- drwxr-xr-x 2026-01-30 00:18:12
Edit Download
- drwxr-xr-x 2026-01-30 00:18:12
Edit Download
- drwxr-xr-x 2026-04-02 15:01:01
Edit Download
16.18 KB lrw-r--r-- 2018-01-14 10:00:21
Edit Download
126 B lrw-r--r-- 2025-07-15 09:13:40
Edit Download
7.95 KB lrw-r--r-- 2018-02-12 08:49:28
Edit Download
348 B lrw-r--r-- 2024-04-06 14:56:52
Edit Download
267 B lrw-r--r-- 2026-04-15 23:46:38
Edit Download
623 B lrw-r--r-- 2025-01-28 01:24:56
Edit Download
242 B lrw-r--r-- 2019-11-19 06:36:19
Edit Download
224.48 KB lrw-r--r-- 2019-11-13 10:36:46
Edit Download
343 B lrw-r--r-- 2024-09-17 10:10:55
Edit Download
30.16 KB lrw-r--r-- 2019-11-13 14:45:19
Edit Download
196 B lrw-r--r-- 2022-10-08 13:05:12
Edit Download
269 B lrw-r--r-- 2022-10-08 13:05:12
Edit Download
31.52 KB lrw-r--r-- 2017-12-21 04:05:00
Edit Download
2.84 KB lrw-r--r-- 2017-12-21 04:05:00
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).