本文整理汇总了Python中socks.PROXY_TYPE_SOCKS4属性的典型用法代码示例。如果您正苦于以下问题:Python socks.PROXY_TYPE_SOCKS4属性的具体用法?Python socks.PROXY_TYPE_SOCKS4怎么用?Python socks.PROXY_TYPE_SOCKS4使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socks
的用法示例。
在下文中一共展示了socks.PROXY_TYPE_SOCKS4属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_proxy
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS4 [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
示例2: __init__
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS4 [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
示例3: __init__
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS4 [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
示例4: __init__
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS4 [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)
示例5: ensure_connected
# 需要导入模块: import socks [as 别名]
# 或者: from socks import PROXY_TYPE_SOCKS4 [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