• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python socks.set_default_proxy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: get_soup_html

def get_soup_html(url):
    socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 1080)
    socket.socket = socks.socksocket
    #伪装一个IE6.0浏览器访问,如果不伪装,谷歌将返回一个403错误
    browser={'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201'}
    # proxy_support = urllib2.ProxyHandler({'http':'http://212.98.137.34:8080'})
    # opener = urllib2.build_opener(proxy_support, urllib2.HTTPHandler)
    # urllib2.install_opener(opener)
    # content = urllib2.urlopen("http://www.baidu.com").read()
    # print(content)
    req = urllib2.Request(url=url,headers=browser)
    #向谷歌翻译发送请求
    count_number=100
    while count_number:
        try:
            # print 1
            response = urllib2.urlopen(req,timeout=3)
            # print 2
            html=response.read()

            soup = BeautifulSoup(html,"html5lib")
            print(html)
            print(soup.prettify())
            # print('-------------------')
            count_number=0
            return soup
        except:
            count_number-=1
    print(url,'download error')
    return BeautifulSoup('',"html5lib")
开发者ID:gzliuyun,项目名称:Translate,代码行数:30,代码来源:test.py


示例17: proxy

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

        Examples:

            >>> context.proxy = 'localhost' #doctest: +ELLIPSIS
            >>> r = remote('google.com', 80)
            Traceback (most recent call last):
            ...
            pwnlib.exception.PwnlibException: Could not connect to google.com on port 80
            >>> 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:arthaud,项目名称:python3-pwntools,代码行数:27,代码来源:__init__.py


示例18: request_pre_auth_code

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


示例19: getRequestsResponse

    def getRequestsResponse(self,url,timeout=5):
        hostname = self.hostname
        if self.protocol == "http":
            http_proxy  = "http://" + hostname
            https_proxy = "https://" + hostname
            ftp_proxy   = "ftp://" + hostname

            proxyDict = {
                          "http"  : http_proxy,
                          "https" : https_proxy,
                          "ftp"   : ftp_proxy
                        }
            return requests.get(url, timeout=timeout, proxies=proxyDict)
        elif self.protocol == "socks":
            default_socket = socket.socket

            ip, port = hostname.split(':')

            SOCKS5_PROXY_HOST = ip
            SOCKS5_PROXY_PORT = int(port)

            socks.set_default_proxy(socks.SOCKS5, SOCKS5_PROXY_HOST, SOCKS5_PROXY_PORT)
            socket.socket = socks.socksocket

            result = requests.get(url, timeout=timeout)

            #reset socket
            socket.socket = default_socket
            return result
开发者ID:kittolau,项目名称:selepy,代码行数:29,代码来源:proxy_manager.py


示例20: check

def check(args):
	if args.username is not None:
		if args.users:
			error("Contradicting Args", "Please use --users in combination with -s.")
		if args.verified:
			error("Contradicting Args", "Please use --verified in combination with -s.")
		if args.userid:
			error("Contradicting Args", "--userid and -u cannot be used together.")
	if args.tweets and args.users:
		error("Contradicting Args", "--users and --tweets cannot be used together.")
	if args.csv and args.output is None:
		error("Error", "Please specify an output file (Example: -o file.csv).")
	if args.proxy_host is not None:
		if args.proxy_host.lower() == "tor":
			import socks, socket
			socks.set_default_proxy(socks.SOCKS5, "localhost", 9050)
			socket.socket = socks.socksocket
		elif args.proxy_port and args.proxy_type:
			if args.proxy_type.lower() == "socks5":
				_type = socks.SOCKS5
			elif args.proxy_type.lower() == "socks4":
				_type = socks.SOCKS4
			elif args.proxy_type.lower() == "http":
				_type = socks.HTTP
			else:
				error("Error", "Proxy type allower are: socks5, socks4 and http.")
			import socks, socket
			socks.set_default_proxy(_type, args.proxy_host, int(args.proxy_port))
			socket.socket = socks.socksocket
		else:
			error("Error", "Please specify --proxy-host, --proxy-port and --proxy-type")
	else:
		if args.proxy_port or args.proxy_type:
			error("Error", "Please specify --proxy-host, --proxy-port and --proxy-type")
开发者ID:fuckup1337,项目名称:twint,代码行数:34,代码来源:twint.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python socks.setdefaultproxy函数代码示例发布时间:2022-05-27
下一篇:
Python socketserver.ThreadingTCPServer类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap