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


Python socks.SOCKS5属性代码示例

本文整理汇总了Python中socks.SOCKS5属性的典型用法代码示例。如果您正苦于以下问题:Python socks.SOCKS5属性的具体用法?Python socks.SOCKS5怎么用?Python socks.SOCKS5使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在socks的用法示例。


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

示例1: update_config

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def update_config(self):
        if int(self.config.PROXY_ENABLE):

            if self.config.PROXY_TYPE == "HTTP":
                proxy_type = socks.HTTP
            elif self.config.PROXY_TYPE == "SOCKS4":
                proxy_type = socks.SOCKS4
            elif self.config.PROXY_TYPE == "SOCKS5":
                proxy_type = socks.SOCKS5
            else:
                self.logger.error("proxy type %s unknown, disable proxy", self.config.PROXY_TYPE)
                raise Exception()

            socks.set_default_proxy(proxy_type, self.config.PROXY_HOST, self.config.PROXY_PORT,
                                    self.config.PROXY_USER,
                                    self.config.PROXY_PASSWD) 
开发者ID:miketwes,项目名称:XX-Net-mini,代码行数:18,代码来源:connect_creator.py

示例2: main

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def main():
    conf = json.load(open("./proxy.conf"))
    if 'gfw_proxy' in conf:
        proxy = conf['gfw_proxy']
        if proxy['type'] == "socks5":
            proxy['type'] = socks.SOCKS5
        elif proxy['type'] == "socks4":
            proxy['type'] = socks.SOCKS4
        else:
            print "Only support SOCKS4/5 proxy."
            return

        print "Start TCP Proxies..."
        for f in TCP_FORWARDS:
            trd = TCP_Proxy_Thread(f['local_port'], f['remote_server'], proxy)
            trd.start()
    else:
        print "gfw_proxy not defined in proxy.conf" 
开发者ID:the729,项目名称:sync-over-the-wall,代码行数:20,代码来源:tracker_proxy.py

示例3: proxy_connect

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def proxy_connect(args):
    """
    Connect to specified proxy
    """
    if args.proxy_host:
        # Setup proxy by monkeypatching the standard lib
        if args.proxy_type.lower() == "socks5" or not args.proxy_type:
            socks.set_default_proxy(
                socks.SOCKS5, args.proxy_host,
                int(args.proxy_port))
        elif args.proxy_type.lower() == "http":
            socks.set_default_proxy(
                socks.HTTP, args.proxy_host,
                int(args.proxy_port))
        elif args.proxy_type.lower() == "socks4":
            socks.set_default_proxy(
                socks.SOCKS4, args.proxy_host,
                int(args.proxy_port))
        else:
            printNicely(
                magenta('Sorry, wrong proxy type specified! Aborting...'))
            sys.exit()
        socket.socket = socks.socksocket 
开发者ID:orakaro,项目名称:rainbowstream,代码行数:25,代码来源:rainbow.py

示例4: load_proxy_config

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def load_proxy_config():
    global default_socket
    if g.config.PROXY_ENABLE:

        if g.config.PROXY_TYPE == "HTTP":
            proxy_type = socks.HTTP
        elif g.config.PROXY_TYPE == "SOCKS4":
            proxy_type = socks.SOCKS4
        elif g.config.PROXY_TYPE == "SOCKS5":
            proxy_type = socks.SOCKS5
        else:
            xlog.error("proxy type %s unknown, disable proxy", g.config.PROXY_TYPE)
            raise Exception()

        socks.set_default_proxy(proxy_type, g.config.PROXY_HOST, g.config.PROXY_PORT,
                                g.config.PROXY_USER, g.config.PROXY_PASSWD) 
开发者ID:miketwes,项目名称:XX-Net-mini,代码行数:18,代码来源:connect_manager.py

示例5: connect

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def connect(self) -> socket:
        try:
            sockt = socks.socksocket(socket.AF_INET, socket.SOCK_STREAM)
            sockt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            if self.proxy is not None:
                sockt.set_proxy(socks.SOCKS5, self.proxy["host"], self.proxy["port"])
            sockt.connect((self.ip, self.port))
            return sockt
        except Exception as e:
            print(e) 
开发者ID:Benehiko,项目名称:ReolinkCameraAPI,代码行数:12,代码来源:RtspClient.py

示例6: socket_SOCKS5_test

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def socket_SOCKS5_test():
    s = socks.socksocket()
    s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081)
    s.connect(("ifconfig.me", 80))
    s.sendall(raw_HTTP_request())
    status = s.recv(2048).splitlines()[0]
    assert status.startswith(b"HTTP/1.1 200") 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:9,代码来源:sockstest.py

示例7: SOCKS5_connect_timeout_test

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def SOCKS5_connect_timeout_test():
    s = socks.socksocket()
    s.settimeout(0.0001)
    s.set_proxy(socks.SOCKS5, "8.8.8.8", 80)
    try:
        s.connect(("ifconfig.me", 80))
    except socks.ProxyConnectionError as e:
        assert str(e.socket_err) == "timed out" 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:10,代码来源:sockstest.py

示例8: SOCKS5_timeout_test

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def SOCKS5_timeout_test():
    s = socks.socksocket()
    s.settimeout(0.0001)
    s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081)
    try:
        s.connect(("ifconfig.me", 4444))
    except socks.GeneralProxyError as e:
        assert str(e.socket_err) == "timed out" 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:10,代码来源:sockstest.py

示例9: socket_SOCKS5_auth_test

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def socket_SOCKS5_auth_test():
    # TODO: add support for this test. Will need a better SOCKS5 server.
    s = socks.socksocket()
    s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081, username="a", password="b")
    s.connect(("ifconfig.me", 80))
    s.sendall(raw_HTTP_request())
    status = s.recv(2048).splitlines()[0]
    assert status.startswith(b"HTTP/1.1 200") 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:10,代码来源:sockstest.py

示例10: socket_SOCKS5_IP_test

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def socket_SOCKS5_IP_test():
    s = socks.socksocket()
    s.set_proxy(socks.SOCKS5, "127.0.0.1", 1081)
    s.connect(("133.242.129.236", 80))
    s.sendall(raw_HTTP_request())
    status = s.recv(2048).splitlines()[0]
    assert status.startswith(b"HTTP/1.1 200") 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:9,代码来源:sockstest.py

示例11: urllib2_handler_SOCKS5_test

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def urllib2_handler_SOCKS5_test():
    opener = urllib2.build_opener(sockshandler.SocksiPyHandler(socks.SOCKS5, "127.0.0.1", 1081))
    status = opener.open("http://ifconfig.me/ip").getcode()
    assert status == 200 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:6,代码来源:sockstest.py

示例12: global_override_SOCKS5_test

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def global_override_SOCKS5_test():
    default_proxy = (socks.SOCKS5, "127.0.0.1", 1081)
    socks.set_default_proxy(*default_proxy)
    good = socket.socket
    socket.socket = socks.socksocket
    status = urllib2.urlopen("http://ifconfig.me/ip").getcode()
    socket.socket = good
    assert status == 200
    assert socks.get_default_proxy()[1].decode() == default_proxy[1] 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:11,代码来源:sockstest.py

示例13: _open_proxied_socket

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def _open_proxied_socket(url, options, proxy):
    hostname, port, resource, is_secure = parse_url(url)

    if not HAS_PYSOCKS:
        raise WebSocketException("PySocks module not found.")

    ptype = socks.SOCKS5
    rdns = False
    if proxy.type == "socks4":
        ptype = socks.SOCKS4
    if proxy.type == "http":
        ptype = socks.HTTP
    if proxy.type[-1] == "h":
        rdns = True

    sock = socks.create_connection(
            (hostname, port),
            proxy_type = ptype,
            proxy_addr = proxy.host,
            proxy_port = proxy.port,
            proxy_rdns = rdns,
            proxy_username = proxy.auth[0] if proxy.auth else None,
            proxy_password = proxy.auth[1] if proxy.auth else None,
            timeout = options.timeout,
            socket_options = DEFAULT_SOCKET_OPTION + options.sockopt
    )

    if is_secure:
        if HAVE_SSL:
            sock = _ssl_socket(sock, options.sslopt, hostname)
        else:
            raise WebSocketException("SSL not available.")

    return sock, (hostname, port, resource) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:36,代码来源:_http.py

示例14: parse_proxy_str

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def parse_proxy_str(proxy_str):
    """
    Returns proxy from given string
    """
    if socks is None:
        raise Exception('Please install PySocks if you want to use a proxy')
    url_parser = urlparse(proxy_str)
    proxy_type = None
    proxy_type_str = url_parser.scheme
    
    if proxy_type_str.lower() == "socks5":
        proxy_type = socks.SOCKS5
    elif proxy_type_str.lower() == "socks4":
        proxy_type = socks.SOCKS4
    elif proxy_type_str.lower() == "https":
        proxy_type = socks.HTTP
    elif proxy_type_str.lower() == "http":
        proxy_type = socks.HTTP
    else:
        raise ValueError("Proxy type %s is not supported" % proxy_type)

    host = url_parser.hostname
    port = url_parser.port

    if host is None:
        raise ValueError("Host parsing error")
    if port is None:
        raise ValueError("Port parsing error")

    user = url_parser.username
    password = url_parser.password

    if user is not None and password is not None:
        proxy = (proxy_type, host, port, True, user, password)
    else:
        proxy = (proxy_type, host, port)
    return proxy 
开发者ID:expectocode,项目名称:telegram-export,代码行数:39,代码来源:utils.py

示例15: test_parse_proxy_str

# 需要导入模块: import socks [as 别名]
# 或者: from socks import SOCKS5 [as 别名]
def test_parse_proxy_str(self):
        host = "127.0.0.1"
        port = 1080
        
        proxy = (socks.SOCKS5, host, port)
        proxy_str = "socks5://127.0.0.1:1080"
        self.assertEqual(parse_proxy_str(proxy_str), proxy)

        proxy_str = "http://127.0.0.1:1080"
        proxy = (socks.HTTP, host, port)
        self.assertEqual(parse_proxy_str(proxy_str), proxy)

        proxy_str = "socks4://login:password@127.0.0.1:1080"
        proxy = (socks.SOCKS4, host, port, True, "login", "password")
        self.assertEqual(parse_proxy_str(proxy_str), proxy)

        proxy_str = "bad_type://login:password@127.0.0.1:1080"
        with self.assertRaises(ValueError):
            parse_proxy_str(proxy_str)

        proxy_str = "bad_type://127.0.0.1"
        with self.assertRaises(ValueError):
            parse_proxy_str(proxy_str)

        proxy_str = "bad_type:127.0.0.1"
        with self.assertRaises(ValueError):
            parse_proxy_str(proxy_str)

        proxy_str = "127.0.0.1:1080"
        with self.assertRaises(ValueError):
            parse_proxy_str(proxy_str) 
开发者ID:expectocode,项目名称:telegram-export,代码行数:33,代码来源:test_utils.py


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