本文整理汇总了Python中socks.PROXY_TYPE_SOCKS5属性的典型用法代码示例。如果您正苦于以下问题:Python socks.PROXY_TYPE_SOCKS5属性的具体用法?Python socks.PROXY_TYPE_SOCKS5怎么用?Python socks.PROXY_TYPE_SOCKS5使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socks
的用法示例。
在下文中一共展示了socks.PROXY_TYPE_SOCKS5属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare_us_proxy
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS5 [as 别名]
def prepare_us_proxy(cookie_handler):
if (addon.getSetting('us_proxy_socks5') == 'true'):
if ((addon.getSetting('us_proxy_pass') is not '') and (addon.getSetting('us_proxy_user') is not '')):
print 'Using socks5 authenticated proxy: ' + addon.getSetting('us_proxy') + ':' + addon.getSetting('us_proxy_port')
socks_handler = SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, addon.getSetting('us_proxy'), int(addon.getSetting('us_proxy_port')), True, addon.getSetting('us_proxy_user'), addon.getSetting('us_proxy_pass'))
opener = urllib2.build_opener(socks_handler, cookie_handler)
else:
print 'Using socks5 proxy: ' + addon.getSetting('us_proxy') + ':' + addon.getSetting('us_proxy_port')
socks_handler = SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, addon.getSetting('us_proxy'), int(addon.getSetting('us_proxy_port')), True)
opener = urllib2.build_opener(socks_handler, cookie_handler)
elif (addon.getSetting('us_proxy_socks5') == 'false'):
us_proxy = 'http://' + addon.getSetting('us_proxy') + ':' + addon.getSetting('us_proxy_port')
proxy_handler = urllib2.ProxyHandler({'http' : us_proxy})
if ((addon.getSetting('us_proxy_pass') is not '') and (addon.getSetting('us_proxy_user') is not '')):
print 'Using authenticated proxy: ' + us_proxy
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, us_proxy, addon.getSetting('us_proxy_user'), addon.getSetting('us_proxy_pass'))
proxy_auth_handler = urllib2.ProxyBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(proxy_handler, proxy_auth_handler, cookie_handler)
else:
print 'Using proxy: ' + us_proxy
opener = urllib2.build_opener(proxy_handler, cookie_handler)
return opener
示例2: _get_proxy
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS5 [as 别名]
def _get_proxy(self):
url_dissected = url_dissector.findall(
self.session['proxy']
)
if url_dissected and len(url_dissected[0]) == 3:
protocol, host, port = url_dissected[0]
if protocol == 'socks5':
return (socks.PROXY_TYPE_SOCKS5, host, int(port))
if protocol == 'socks4':
return (socks.PROXY_TYPE_SOCKS4, host, int(port))
if protocol.startswith('http'):
return (socks.PROXY_TYPE_HTTP, host, int(port))
return None, None, None
示例3: __init__
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS5 [as 别名]
def __init__(self, proxy_url, username=None, password=None,
num_pools=10, headers=None, **connection_pool_kw):
parsed = parse_url(proxy_url)
if parsed.scheme == 'socks5':
socks_version = socks.PROXY_TYPE_SOCKS5
rdns = False
elif parsed.scheme == 'socks5h':
socks_version = socks.PROXY_TYPE_SOCKS5
rdns = True
elif parsed.scheme == 'socks4':
socks_version = socks.PROXY_TYPE_SOCKS4
rdns = False
elif parsed.scheme == 'socks4a':
socks_version = socks.PROXY_TYPE_SOCKS4
rdns = True
else:
raise ValueError(
"Unable to determine SOCKS version from %s" % proxy_url
)
self.proxy_url = proxy_url
socks_options = {
'socks_version': socks_version,
'proxy_host': parsed.host,
'proxy_port': parsed.port,
'username': username,
'password': password,
'rdns': rdns
}
connection_pool_kw['_socks_options'] = socks_options
super(SOCKSProxyManager, self).__init__(
num_pools, headers, **connection_pool_kw
)
self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme
示例4: __init__
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS5 [as 别名]
def __init__(self, proxy_url, username=None, password=None,
num_pools=10, headers=None, **connection_pool_kw):
parsed = parse_url(proxy_url)
if parsed.scheme == 'socks5':
socks_version = socks.PROXY_TYPE_SOCKS5
elif parsed.scheme == 'socks4':
socks_version = socks.PROXY_TYPE_SOCKS4
else:
raise ValueError(
"Unable to determine SOCKS version from %s" % proxy_url
)
self.proxy_url = proxy_url
socks_options = {
'socks_version': socks_version,
'proxy_host': parsed.host,
'proxy_port': parsed.port,
'username': username,
'password': password,
}
connection_pool_kw['_socks_options'] = socks_options
super(SOCKSProxyManager, self).__init__(
num_pools, headers, **connection_pool_kw
)
self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme
示例5: prepare_tor_proxy
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS5 [as 别名]
def prepare_tor_proxy(cookie_handler):
if addon.getSetting('tor_use_local') == 'true':
tor_proxy = '127.0.0.1'
else:
tor_proxy = addon.getSetting('tor_proxy')
print 'Using tor proxy at ' + tor_proxy + ':' + addon.getSetting('tor_socks_port') + ' with exit node: ' + addon.getSetting('tor_exit_node')
socks_handler = SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, tor_proxy, int(addon.getSetting('tor_socks_port')), True)
opener = urllib2.build_opener(socks_handler, cookie_handler)
return opener
示例6: __init__
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS5 [as 别名]
def __init__(self, _=None):
"""Build self._urllib_opener"""
proxy = super().__str__()
if proxy == "None":
self._urllib_opener = build_opener()
return
components = list(re.match(self._match_regexp, proxy).groups())
self.scheme, self.host, self.port = components
self.components = components
if self.scheme == "socks4":
socks4_handler = SocksiPyHandler(socks.PROXY_TYPE_SOCKS4,
self.host,
int(self.port))
self._urllib_opener = build_opener(socks4_handler)
elif self.scheme == "socks5":
socks5_handler = SocksiPyHandler(socks.PROXY_TYPE_SOCKS5,
self.host,
int(self.port))
self._urllib_opener = build_opener(socks5_handler)
else:
proxy_handler = ProxyHandler({'http': proxy, 'https': proxy})
self._urllib_opener = build_opener(proxy_handler)
示例7: ensure_connected
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS5 [as 别名]
def ensure_connected(self, connection, proto, host):
if connection != None and connection.sock != None:
return connection, False
if proto == 'https': connector = httplib.HTTPSConnection
else: connector = httplib.HTTPConnection
if not self.options.proxy:
return connector(host, strict=True), True
host, port = host.split(':')
proxy_proto, user, pwd, proxy_host = self.options.proxy[:4]
proxy_port = 9050
proxy_host = proxy_host.split(':')
if len(proxy_host) > 1:
proxy_port = int(proxy_host[1]); proxy_host = proxy_host[0]
connection = connector(host, strict=True)
connection.sock = socks.socksocket()
proxy_type = socks.PROXY_TYPE_SOCKS5
if proxy_proto == 'http':
proxy_type = socks.PROXY_TYPE_HTTP
elif proxy_proto == 'socks4':
proxy_type = socks.PROXY_TYPE_SOCKS4
connection.sock.setproxy(proxy_type, proxy_host, proxy_port, True, user, pwd)
try:
connection.sock.connect((host, int(port)))
except socks.Socks5AuthError:
say_exception('Proxy error:')
self.stop()
return connection, True