我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用socks.HTTP。
def init_proxy(proxy): res = urlparse(proxy) use_proxy = True if res.scheme == 'socks4': mode = socks.SOCKS4 elif res.scheme == 'socks5': mode = socks.SOCKS5 elif res.scheme == 'http': mode = socks.HTTP else: use_proxy = False ksprint.print_error('Unknown proxy "%s", starting without proxy...' % proxy) if use_proxy: socks.set_default_proxy(mode, res.netloc.split(':')[0], int(res.netloc.split(':')[1])) soc.socket = socks.socksocket ksprint.print_success('[*] Proxy "%s" using' % proxy)
def load_proxy_config(): global default_socket if config.PROXY_ENABLE: if config.PROXY_TYPE == "HTTP": proxy_type = socks.HTTP elif config.PROXY_TYPE == "SOCKS4": proxy_type = socks.SOCKS4 elif config.PROXY_TYPE == "SOCKS5": proxy_type = socks.SOCKS5 else: xlog.error("proxy type %s unknown, disable proxy", config.PROXY_TYPE) raise socks.set_default_proxy(proxy_type, config.PROXY_HOST, config.PROXY_PORT, config.PROXY_USER, config.PROXY_PASSWD)
def check_goagent(ssl_sock, appid): request_data = 'GET /_gh/ HTTP/1.1\r\nHost: %s.appspot.com\r\n\r\n' % appid ssl_sock.send(request_data.encode()) response = httplib.HTTPResponse(ssl_sock, buffering=True) response.begin() server_type = response.getheader('Server', "") xlog.debug("status:%d", response.status) xlog.debug("Server type:%s", server_type) if response.status == 404: xlog.warn("app check %s status:%d", appid, response.status) return False if response.status == 503: # out of quota if "gws" not in server_type and "Google Frontend" not in server_type and "GFE" not in server_type: xlog.warn("503 but server type:%s", server_type) return False else: xlog.info("503 server type:%s", server_type) return True if response.status != 200: xlog.warn("app check %s ip:%s status:%d", appid, ip, response.status) return False content = response.read() if "GoAgent" not in content: xlog.warn("app check %s content:%s", appid, content) return False xlog.info("check_goagent ok") return True
def load_proxy_config(): if config.PROXY_ENABLE: if config.PROXY_TYPE == "HTTP": proxy_type = socks.HTTP elif config.PROXY_TYPE == "SOCKS4": proxy_type = socks.SOCKS4 elif config.PROXY_TYPE == "SOCKS5": proxy_type = socks.SOCKS5 else: xlog.error("proxy type %s unknown, disable proxy", config.PROXY_TYPE) config.PROXY_ENABLE = 0 return socks.set_default_proxy(proxy_type, config.PROXY_HOST, config.PROXY_PORT, config.PROXY_USER, config.PROXY_PASSWD)