aboutsummaryrefslogtreecommitdiffstats
path: root/python/sockshandler.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-09-06 16:31:13 -0700
committerJames Taylor <user234683@users.noreply.github.com>2019-09-06 16:31:13 -0700
commit3d57e14df7ba5f14a634295caf3b2e60da50bfe2 (patch)
tree4903bcb79a49ad714a1a9129765b9545405c9978 /python/sockshandler.py
parentac32b24b2a011292b704a3f27e8fd08a7ae9424b (diff)
downloadyt-local-3d57e14df7ba5f14a634295caf3b2e60da50bfe2.tar.lz
yt-local-3d57e14df7ba5f14a634295caf3b2e60da50bfe2.tar.xz
yt-local-3d57e14df7ba5f14a634295caf3b2e60da50bfe2.zip
Remove windows python distribution from repo and add requirements.txt
Diffstat (limited to 'python/sockshandler.py')
-rw-r--r--python/sockshandler.py79
1 files changed, 0 insertions, 79 deletions
diff --git a/python/sockshandler.py b/python/sockshandler.py
deleted file mode 100644
index 26c8343..0000000
--- a/python/sockshandler.py
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/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())