当前位置: 首页>>代码示例>>Python>>正文


Python socks.set_default_proxy函数代码示例

本文整理汇总了Python中socks.set_default_proxy函数的典型用法代码示例。如果您正苦于以下问题:Python set_default_proxy函数的具体用法?Python set_default_proxy怎么用?Python set_default_proxy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了set_default_proxy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: web_page

 def web_page(self, mode, string, public_mode):
     '''Test that the web page contains a string'''
     (socks_address, socks_port) = self.gui.app.onion.get_tor_socks_port()
     socks.set_default_proxy(socks.SOCKS5, socks_address, socks_port)
     s = socks.socksocket()
     s.settimeout(60)
     s.connect((self.gui.app.onion_host, 80))
     if not public_mode:
         path = '/{}'.format(mode.server_status.web.slug)
     else:
         path = '/'
     http_request = 'GET {} HTTP/1.0\r\n'.format(path)
     http_request += 'Host: {}\r\n'.format(self.gui.app.onion_host)
     http_request += '\r\n'
     s.sendall(http_request.encode('utf-8'))
     with open('/tmp/webpage', 'wb') as file_to_write:
         while True:
            data = s.recv(1024)
            if not data:
                break
            file_to_write.write(data)
         file_to_write.close()
     f = open('/tmp/webpage')
     self.assertTrue(string in f.read())
     f.close()
开发者ID:micahflee,项目名称:onionshare,代码行数:25,代码来源:TorGuiBaseTest.py

示例2: get_media

 def get_media(self, media_id):
     default_socket = socket.socket
     socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
     socket.socket = socks.socksocket
     r = super(WXMPAPI2, self).get_media(media_id)
     socket.socket = default_socket
     return r
开发者ID:richmonkey,项目名称:xiaowei_web,代码行数:7,代码来源:wx.py

示例3: scan

def scan():
    SOCKS_PROXY_HOST = '127.0.0.1'
    SOCKS_PROXY_PORT = 1234
    HEADER = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36'}
    ip_port = [22, 80, 443, 3389, 6379, 7001, 8080, 27017]


    default_socket = socket.socket
    socks.set_default_proxy(socks.SOCKS5, SOCKS_PROXY_HOST,SOCKS_PROXY_PORT)
    socket.socket = socks.socksocket
    while True:
        if queue.empty():
            break
        reqIp = queue.get_nowait()
        for port in ip_port:
            reqUrl = 'http://'+str(reqIp)+':'+str(port)
            print 'scanning '+reqUrl
            try:
                res = requests.get(reqUrl,headers=HEADER,timeout=5)
                html = res.text 
            except Exception,e:
                print 'get html error'
                continue
            if html:
                print 'ok'
                success_list.append(reqUrl)
开发者ID:kovige,项目名称:NetScan,代码行数:26,代码来源:net_scan.py

示例4: send_message

 def send_message(self, data):
     default_socket = socket.socket
     socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
     socket.socket = socks.socksocket
     r = super(WXMPAPI2, self).send_message(data)
     socket.socket = default_socket
     return r
开发者ID:richmonkey,项目名称:xiaowei_web,代码行数:7,代码来源:wx.py

示例5: get_user_by_openid

 def get_user_by_openid(self, openid):
     default_socket = socket.socket
     socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
     socket.socket = socks.socksocket
     r = super(WXMPAPI2, self).get_user_by_openid(openid)
     socket.socket = default_socket
     return r
开发者ID:richmonkey,项目名称:xiaowei_web,代码行数:7,代码来源:wx.py

示例6: request_info

 def request_info(self, appid):
     default_socket = socket.socket
     socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
     socket.socket = socks.socksocket
     r = super(WXOpenAPI2, self).request_info(appid)
     socket.socket = default_socket
     return r
开发者ID:richmonkey,项目名称:xiaowei_web,代码行数:7,代码来源:wx.py

示例7: refresh_auth

 def refresh_auth(self, auth_appid, refresh_token):
     default_socket = socket.socket
     socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
     socket.socket = socks.socksocket
     r = super(WXOpenAPI2, self).refresh_auth(auth_appid, refresh_token)
     socket.socket = default_socket
     return r
开发者ID:richmonkey,项目名称:xiaowei_web,代码行数:7,代码来源:wx.py

示例8: request_auth

 def request_auth(self, authorization_code):
     default_socket = socket.socket
     socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
     socket.socket = socks.socksocket
     r = super(WXOpenAPI2, self).request_auth(authorization_code)
     socket.socket = default_socket
     return r
开发者ID:richmonkey,项目名称:xiaowei_web,代码行数:7,代码来源:wx.py

示例9: getProxy

def getProxy():
    #socks5访问pachong.org
    socks.set_default_proxy(socks.SOCKS5,'127.0.0.1',1080)
    socket.socket = socks.socksocket
    r = requesocks.get(proxyUrl)
    html = r.text.encode('utf-8')
    #匹配 网页定义的js声明
    reg_script_head = '<script type.*?>(.*?)</script>'
    pattern_script_head = re.compile(reg_script_head,re.S)
    result_of_script_head = re.findall(pattern_script_head,html)

    #匹配ip端口
    reg_port = '<td><script>(.*?)</script>'
    pattern_port = re.compile(reg_port,re.S)
    result_of_port = re.findall(pattern_port,html)

    #匹配ip地址
    reg_ip = '<td>([0-9]+(?:\.[0-9]+){0,3})</td>'
    pattern_ip = re.compile(reg_ip,re.S)
    result_of_ip = re.findall(pattern_ip,html)

    for i,item in enumerate(result_of_ip):
        jsevalPort = result_of_script_head[2] + result_of_port[i]
        js = ''' function add(){
        %s
        }
        add()''' % jsevalPort.replace('document.write','return')
        result = js2py.eval_js(js)
        ip_port[item] = result
开发者ID:xczswt1993,项目名称:Spider,代码行数:29,代码来源:proxyList.py

示例10: __init__

    def __init__(self, master, worker_name, bot_name, server, access_token, port=6667, proxy=None):
        self.master = master
        self.worker_name = worker_name
        self.command = "!"+self.master.bot_name
        self.started = False
        self.is_connected = False

        if proxy is not None:
            logging.info('[%s] Proxy set: %s:%s', self.worker_name, proxy["address"], proxy["port"])
            socks.set_default_proxy(socks.HTTP, proxy["address"], proxy["port"])
            socket.socket = socks.socksocket

        SingleServerIRCBot.__init__(self, [(server, port, access_token)], bot_name, bot_name)

        # keep ip for logging
        self.proxy_name = socket.gethostbyname(socket.getfqdn())

        # Channels set up
        self.channels = IRCDict()
        self.channel_join_queue = Queue.Queue()
        self.channel_list = []

        # Messages set up
        self.user_message_queue = Queue.Queue()

        self.log('Chat worker bot initialized.')
开发者ID:carriercomm,项目名称:changetip-twitch,代码行数:26,代码来源:chat_worker.py

示例11: proxy

    def proxy(self, proxy):
        """
        Default proxy for all socket connections.

        Accepts either a string (hostname or IP address) for a SOCKS5 proxy on
        the default port, **or** a ``tuple`` passed to ``socks.set_default_proxy``,
        e.g. ``(socks.SOCKS4, 'localhost', 1234)``.

        >>> context.proxy = 'localhost' #doctest: +ELLIPSIS
        >>> r=remote('google.com', 80)
        Traceback (most recent call last):
        ...
        ProxyConnectionError: Error connecting to SOCKS5 proxy localhost:1080: [Errno 111] Connection refused

        >>> context.proxy = None
        >>> r=remote('google.com', 80, level='error')
        """

        if not proxy:
            socket.socket = _original_socket
            return None

        if isinstance(proxy, str):
            proxy = (socks.SOCKS5, proxy)

        if not isinstance(proxy, collections.Iterable):
            raise AttributeError('proxy must be a string hostname, or tuple of arguments for socks.set_default_proxy')

        socks.set_default_proxy(*proxy)
        socket.socket = socks.socksocket

        return proxy
开发者ID:Eadom,项目名称:binjitsu,代码行数:32,代码来源:__init__.py

示例12: getSource

def getSource(url, headers={}, proxy=None, maxRetrys=2, timeWait=2):
    if proxy:
        if PY_SOCKS:
            proxy = proxy.split(':')
            socks.set_default_proxy(socks.SOCKS4, proxy[0], int(proxy[1]))
            socket.socket = socks.socksocket
        else:
            print "\nCan't use proxy because pysocks is missing !?"

    socket.setdefaulttimeout(40)
    source = None
    while not source:
        try:
            request = urllib2.Request(url, headers=headers)
            respond = urllib2.urlopen(request)
            encoding = respond.headers.get('Content-Encoding')
            if not encoding:
                source = respond.read()
            elif encoding.lower() == 'gzip':
                pageBytes = io.BytesIO(respond.read())
                gzibFile = gzip.GzipFile(fileobj=pageBytes)
                source = gzibFile.read()
            else:
                raise urllib2.URLError('unknown encoding !!')
                break
        except (urllib2.URLError, IOError):
            if maxRetrys == 0:
                raise urllib2.URLError("Can't connect !!")
                break
            else:
                time.sleep(random.uniform(0.5 * timeWait, 1.5 * timeWait))
                maxRetrys -= 1

    socket.setdefaulttimeout(None)
    return source
开发者ID:omerkun,项目名称:PyPerv,代码行数:35,代码来源:PyPerv.py

示例13: main

def main():
    args = parse_argument()

    try:
        if args.socks5[0] and args.socks5[1]:
            if args.proxy:
                logger.error('invalid proxy protocol count.')
                raise SystemExit
            socks.set_default_proxy(socks.SOCKS5, args.socks5[0], int(args.socks5[1]),
                                    True, args.socks5[2], args.socks5[3])
            socket.socket = socks.socksocket
    except Exception as e:
        logger.error('invalid socks5 proxy arguments.')
        raise SystemExit

    t = Thread(args.board, args.thread)
    if not args.downloading:
        thread_info = t.thread_info()
        logger.info('/{}/ - {} - {}'.format(args.board, thread_info['sub'], const.BOARDS[args.board]))
        logger.info('total images - {}'.format(thread_info['images']))
    else:
        downloader = Downloader(path=args.path, threads=args.threads, timeout=args.timeout,
                                is_thumb=args.thumb)
        q = t.detail_queue()
        downloader.fetch(q)
开发者ID:Pasithea,项目名称:4chan-dl,代码行数:25,代码来源:entry.py

示例14: global_override_HTTP_test

def global_override_HTTP_test():
    socks.set_default_proxy(socks.HTTP, "127.0.0.1", 8080)
    good = socket.socket
    socket.socket = socks.socksocket
    status = urllib2.urlopen("http://api.externalip.net/ip/").getcode()
    socket.socket = good
    assert status == 200
开发者ID:ifeco2,项目名称:PySocks,代码行数:7,代码来源:sockstest.py

示例15: global_override_HTTP_test

def global_override_HTTP_test():
    socks.set_default_proxy(socks.HTTP, "127.0.0.1", 8081)
    good = socket.socket
    socket.socket = socks.socksocket
    status = urllib2.urlopen("http://ifconfig.me/ip").getcode()
    socket.socket = good
    assert status == 200
开发者ID:Konubinix,项目名称:PySocks,代码行数:7,代码来源:sockstest.py


注:本文中的socks.set_default_proxy函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。