本文整理汇总了Python中urllib3.contrib.socks.SOCKSProxyManager方法的典型用法代码示例。如果您正苦于以下问题:Python socks.SOCKSProxyManager方法的具体用法?Python socks.SOCKSProxyManager怎么用?Python socks.SOCKSProxyManager使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib3.contrib.socks
的用法示例。
在下文中一共展示了socks.SOCKSProxyManager方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GetExternalIP
# 需要导入模块: from urllib3.contrib import socks [as 别名]
# 或者: from urllib3.contrib.socks import SOCKSProxyManager [as 别名]
def GetExternalIP(self, proxy=None):
timeout = self.timeout.get()
file = "Data/tordata%s/ip.txt" % (proxy-9050)
url = 'http://checkip.amazonaws.com'
interval = int(self.time.get()-1)
soc = SOCKSProxyManager('socks5://127.0.0.1:%s/' % proxy)
s = soc.request('GET', url, timeout=urllib3.Timeout(connect=interval, read=interval), retries=False)
d = s.data.decode('utf-8').split('\n')
f = open(file, 'w')
f.write(d[0])
f.close()
s.close()
#funkce na zjisteni odezvy pro zjistenou IP adresu, nejdrive zavola zjisteni IP a nasledne provede overeni odezvy, a vypise vystup do aplikace
示例2: pageRequest
# 需要导入模块: from urllib3.contrib import socks [as 别名]
# 或者: from urllib3.contrib.socks import SOCKSProxyManager [as 别名]
def pageRequest(url):
global roundRobin
proxy = SOCKSProxyManager('socks5://localhost:'+str(torPort),
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(),
headers={'user-agent': randomUserAgent(), 'Cookie': ''})
http = urllib3.PoolManager( 1,
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(),
headers={'user-agent': randomUserAgent(), 'Cookie': ''})
if roundRobin % 2:
response = http.request('GET', url)
else:
if torSupport:
response = proxy.request('GET', url)
else:
response = http.request('GET', url)
roundRobin += 1
if not roundRobin % 60:
newTorIdentity()
return response.data
示例3: __init__
# 需要导入模块: from urllib3.contrib import socks [as 别名]
# 或者: from urllib3.contrib.socks import SOCKSProxyManager [as 别名]
def __init__(self, url, user_agent, cookies_string=False, custom_header=False, insecure_ssl='false', proxy=False):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
self.__url = url
self.__headers = dict()
self.__headers['User-Agent'] = self.__default_user_agent if user_agent == 'default' else user_agent
if cookies_string:
self.__headers['Cookie'] = cookies_string
if custom_header:
self.__parse_custom_header(custom_header)
self.__verify = 'CERT_REQUIRED' if insecure_ssl == 'false' else 'CERT_NONE'
if proxy:
proxy_type = proxy.split('://')[0]
if proxy_type == 'http' or proxy_type == 'https':
self.__request_obj = urllib3.ProxyManager(proxy, ssl_version=ssl.PROTOCOL_TLSv1,
timeout=self.__request_timeout, cert_reqs=self.__verify)
else:
self.__request_obj = SOCKSProxyManager(proxy, ssl_version=ssl.PROTOCOL_TLSv1,
timeout=self.__request_timeout, cert_reqs=self.__verify)
else:
self.__request_obj = urllib3.PoolManager(ssl_version=ssl.PROTOCOL_TLSv1, timeout=self.__request_timeout,
cert_reqs=self.__verify)
# print (vars(self))
示例4: SOCKSProxyManager
# 需要导入模块: from urllib3.contrib import socks [as 别名]
# 或者: from urllib3.contrib.socks import SOCKSProxyManager [as 别名]
def SOCKSProxyManager(*args, **kwargs):
raise InvalidSchema("Missing dependencies for SOCKS support.")
示例5: proxy_manager_for
# 需要导入模块: from urllib3.contrib import socks [as 别名]
# 或者: from urllib3.contrib.socks import SOCKSProxyManager [as 别名]
def proxy_manager_for(self, proxy, **proxy_kwargs):
"""Return urllib3 ProxyManager for the given proxy.
This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param proxy: The proxy to return a urllib3 ProxyManager for.
:param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
:returns: ProxyManager
:rtype: urllib3.ProxyManager
"""
if proxy in self.proxy_manager:
manager = self.proxy_manager[proxy]
elif proxy.lower().startswith('socks'):
username, password = get_auth_from_url(proxy)
manager = self.proxy_manager[proxy] = SOCKSProxyManager(
proxy,
username=username,
password=password,
num_pools=self._pool_connections,
maxsize=self._pool_maxsize,
block=self._pool_block,
**proxy_kwargs
)
else:
proxy_headers = self.proxy_headers(proxy)
manager = self.proxy_manager[proxy] = proxy_from_url(
proxy,
proxy_headers=proxy_headers,
num_pools=self._pool_connections,
maxsize=self._pool_maxsize,
block=self._pool_block,
**proxy_kwargs)
return manager
示例6: __init__
# 需要导入模块: from urllib3.contrib import socks [as 别名]
# 或者: from urllib3.contrib.socks import SOCKSProxyManager [as 别名]
def __init__(self, handler, range_start, range_end):
self.handler = handler
self.write = handler.wfile.write
self.url = handler.url
self.scheme = handler.url_parts.scheme
self.netloc = handler.url_parts.netloc
self.headers = dict((k.title(), v) for k, v in handler.headers.items())
self.headers['Host'] = self.netloc
self.headers.update(fake_headers)
self.range_start = range_start
self.range_end = range_end
self.delay_cache_size = self.max_size * self.threads * 4
self.delay_star_size = self.delay_cache_size * 2
self.max_threads = min(self.threads * 2, self.pool_size)
if self.http is None:
connection_pool_kw = {
'block': True,
'timeout': self.timeout,
'maxsize': self.pool_size
}
if self.proxy:
if self.proxy.lower().startswith('socks'):
from urllib3.contrib.socks import SOCKSProxyManager as ProxyManager
else:
ProxyManager = urllib3.ProxyManager
http = ProxyManager(self.proxy, **connection_pool_kw)
if ProxyManager is not urllib3.ProxyManager:
http.connection_pool_kw['_socks_options']['rdns'] = True
else:
http = urllib3.PoolManager(**connection_pool_kw)
self.__class__.http = http
self.firstrange = range_start, range_start + self.first_size - 1
self.data_queue = Queue.PriorityQueue()
self.range_queue = Queue.LifoQueue()
self._started_threads = {}
示例7: get_tor_session
# 需要导入模块: from urllib3.contrib import socks [as 别名]
# 或者: from urllib3.contrib.socks import SOCKSProxyManager [as 别名]
def get_tor_session(self):
"""
Configures and create the session to use a Tor Socks proxy.
:return: urllib3.SOCKSProxyManager object.
"""
user_agent = {'user-agent':
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'}
session = SOCKSProxyManager('socks5://{0}:{1}'.format(self.ip, self.socksport), cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where(), headers=user_agent)
return session