/usr/share/cagefs-skeleton/lib/python3.9/site-packages
#!/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 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 def is_ip(s): try: if ':' in s: socket.inet_pton(socket.AF_INET6, s) elif '.' in s: socket.inet_aton(s) else: return False except: return False else: return True socks4_no_rdns = set() 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): (proxytype, proxyaddr, proxyport, rdns, username, password) = self.proxyargs rdns = rdns and proxyaddr not in socks4_no_rdns while True: try: sock = socks.create_connection( (self.host, self.port), self.timeout, None, proxytype, proxyaddr, proxyport, rdns, username, password, ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)) break except socks.SOCKS4Error as e: if rdns and "0x5b" in str(e) and not is_ip(self.host): # Maybe a SOCKS4 server that doesn't support remote resolving # Let's try again rdns = False socks4_no_rdns.add(proxyaddr) else: raise self.sock = sock 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): SocksiPyConnection.connect(self) self.sock = self._context.wrap_socket(self.sock, server_hostname=self.host) if not self._context.check_hostname and self._check_hostname: try: ssl.match_hostname(self.sock.getpeercert(), self.host) except Exception: self.sock.shutdown(socket.SHUT_RDWR) self.sock.close() raise 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())
.
Edit
..
Edit
CHANGELOG.rst
Edit
CONTRIBUTING.md
Edit
ConfigArgParse-1.7.1.dist-info
Edit
Glances-3.3.1.dist-info
Edit
OpenSSL
Edit
PySocks-1.7.1-py3.9.egg-info
Edit
__pycache__
Edit
_distutils_hack
Edit
_version.py
Edit
acme
Edit
acme-3.1.0.dist-info
Edit
bottle-0.12.21-py3.9.egg-info
Edit
bottle.py
Edit
certbot
Edit
certbot-3.1.0.dist-info
Edit
chardet
Edit
chardet-4.0.0.dist-info
Edit
configargparse.py
Edit
configobj-5.0.6-py3.9.egg-info
Edit
configobj.py
Edit
dateutil
Edit
defusedxml
Edit
defusedxml-0.7.1-py3.9.egg-info
Edit
distro-1.5.0-py3.9.egg-info
Edit
distro.py
Edit
distutils-precedence.pth
Edit
dnf
Edit
dnf-plugins
Edit
dnfpluginscore
Edit
dns
Edit
dnspython-2.6.1-py3.9.egg-info
Edit
firewall
Edit
future
Edit
future-0.18.3-py3.9.egg-info
Edit
gi
Edit
glances
Edit
html2text
Edit
html2text-2020.1.16-py3.9.egg-info
Edit
hwdata.py
Edit
idna
Edit
idna-2.10-py3.9.egg-info
Edit
importlib_metadata
Edit
importlib_metadata-4.12.0.dist-info
Edit
iotop
Edit
iotop-0.6-py3.9.egg-info
Edit
isc
Edit
isc-2.0-py3.9.egg-info
Edit
josepy
Edit
josepy-1.14.0.dist-info
Edit
libfuturize
Edit
libpasteurize
Edit
nftables
Edit
nftables-0.1.dist-info
Edit
parsedatetime
Edit
parsedatetime-2.6-py3.9.egg-info
Edit
past
Edit
pciutils-2.3.7-py3.9.egg-info
Edit
pip
Edit
pip-21.3.1.dist-info
Edit
pkg_resources
Edit
ply
Edit
ply-3.11-py3.9.egg-info
Edit
procfs
Edit
pyOpenSSL-21.0.0-py3.9.egg-info
Edit
pyRFC3339-1.1.dist-info
Edit
pycparser
Edit
pycparser-2.20-py3.9.egg-info
Edit
pygtkcompat
Edit
pyinotify-0.9.6-py3.9.egg-info
Edit
pyinotify.py
Edit
pyrfc3339
Edit
python_dateutil-2.8.1-py3.9.egg-info
Edit
python_linux_procfs-0.7.3-py3.9.egg-info
Edit
pytz
Edit
pytz-2021.1-py3.9.egg-info
Edit
pyudev
Edit
pyudev-0.22.0-py3.9.egg-info
Edit
requests
Edit
requests-2.25.1.dist-info
Edit
rhn
Edit
rhnlib-2.8.6-py3.9.egg-info
Edit
seobject.py
Edit
sepolgen
Edit
sepolicy
Edit
sepolicy-3.6-py3.9.egg-info
Edit
setuptools
Edit
setuptools-53.0.0.dist-info
Edit
six-1.15.0.dist-info
Edit
six.py
Edit
socks.py
Edit
sockshandler.py
Edit
tuned
Edit
up2date_client
Edit
urllib3
Edit
urllib3-1.26.5-py3.9.egg-info
Edit
validate.py
Edit
zipp
Edit
zipp-3.20.1.dist-info
Edit