Python socket.IPPROTO_TCP属性代码示例

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

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

示例1: _start

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def _start(self):
        def try_address(address):
            try:
                (ip_address, port) = address
                index = 0
                for info in socket.getaddrinfo(ip_address, port, socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP):
                    try:
                        with self._lock:
                            self._found.append((info[4][0], info[4][1]))
                    except Exception, e:
                        pass
                    # snooze for some time, so each dns_seed has a chance
                    # to add nodes, and get addresses from those nodes
                    #snooze = -1 + 1.3 ** index
                    #if snooze > 600: snooze = 600 + random.randint(0, 120)
                    #index += 1
                    #time.sleep(snooze)
            except Exception, e:
                pass 
开发者ID:ricmoo,项目名称:pycoind,代码行数:24,代码来源:bootstrap.py


示例2: bind

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def bind(self, family, type, proto=0):
        """Create (or recreate) the actual socket object."""
        self.socket = socket.socket(family, type, proto)
        prevent_socket_inheritance(self.socket)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if self.nodelay and not isinstance(self.bind_addr, str):
            self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        if self.ssl_adapter is not None:
            self.socket = self.ssl_adapter.bind(self.socket)
        # If listening on the IPV6 any address ('::' = IN6ADDR_ANY),
        # activate dual-stack. See https://bitbucket.org/cherrypy/cherrypy/issue/871.
        if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6
            and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')):
            try:
                self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
            except (AttributeError, socket.error):
                # Apparently, the socket option is not available in
                # this machine's TCP stack
                pass
        self.socket.bind(self.bind_addr) 
开发者ID:exiahuang,项目名称:SalesforceXyTools,代码行数:25,代码来源:wsgiserver3.py


示例3: _socks_connection

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def _socks_connection(host, port, timeout, socks_config):
    """Create a SOCKS connection based on the supplied configuration."""
    try:
        socks_type = dict(
            socks4=socks.PROXY_TYPE_SOCKS4,
            socks5=socks.PROXY_TYPE_SOCKS5,
            socks5h=socks.PROXY_TYPE_SOCKS5
        )[socks_config.scheme]
    except KeyError:
        raise TypeError('Invalid SOCKS scheme: {}'.format(socks_config.scheme))
    socks_host, socks_port = socks_config.hostport.split(':')
    return socks.create_connection(
        (host, port),
        timeout,
        None,
        socks_type,
        socks_host,
        int(socks_port),
        socks_config.scheme == 'socks5h',
        socks_config.username,
        socks_config.password,
        ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
    ) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:27,代码来源:proxy2.py


示例4: test_connect_uses_socks5_proxy

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def test_connect_uses_socks5_proxy(self, mock_socks):
        conf = namedtuple('ProxyConf', 'scheme username password hostport')
        self.config = {
            'http': conf(*_parse_proxy('socks5://socks_user:socks_pass@socks_host:3128')),
            'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }
        mock_socks.PROXY_TYPE_SOCKS5 = socks.PROXY_TYPE_SOCKS5
        conn = ProxyAwareHTTPConnection(self.config, 'example.com')
        conn.connect()
        mock_socks.create_connection.assert_called_once_with(
            ('example.com', 80),
            socket._GLOBAL_DEFAULT_TIMEOUT,
            None,
            socks.PROXY_TYPE_SOCKS5,
            'socks_host',
            3128,
            False,
            'socks_user',
            'socks_pass',
            ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
        ) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:25,代码来源:test_proxy2.py


示例5: test_connect_uses_remote_dns

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def test_connect_uses_remote_dns(self, mock_socks):
        conf = namedtuple('ProxyConf', 'scheme username password hostport')
        self.config = {
            'http': conf(*_parse_proxy('socks5h://socks_user:socks_pass@socks_host:3128')),
            'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }
        mock_socks.PROXY_TYPE_SOCKS5 = socks.PROXY_TYPE_SOCKS5
        conn = ProxyAwareHTTPConnection(self.config, 'example.com')
        conn.connect()
        mock_socks.create_connection.assert_called_once_with(
            ('example.com', 80),
            socket._GLOBAL_DEFAULT_TIMEOUT,
            None,
            socks.PROXY_TYPE_SOCKS5,
            'socks_host',
            3128,
            True,
            'socks_user',
            'socks_pass',
            ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
        ) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:25,代码来源:test_proxy2.py


示例6: test_connect_uses_socks4_proxy

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def test_connect_uses_socks4_proxy(self, mock_socks):
        conf = namedtuple('ProxyConf', 'scheme username password hostport')
        self.config = {
            'http': conf(*_parse_proxy('socks4://socks_user:socks_pass@socks_host:3128')),
            'no_proxy': 'localhost,127.0.0.1,dev_server:8080'
        }
        mock_socks.PROXY_TYPE_SOCKS4 = socks.PROXY_TYPE_SOCKS4
        conn = ProxyAwareHTTPConnection(self.config, 'example.com')
        conn.connect()
        mock_socks.create_connection.assert_called_once_with(
            ('example.com', 80),
            socket._GLOBAL_DEFAULT_TIMEOUT,
            None,
            socks.PROXY_TYPE_SOCKS4,
            'socks_host',
            3128,
            False,
            'socks_user',
            'socks_pass',
            ((socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),)
        ) 
开发者ID:wkeeling,项目名称:selenium-wire,代码行数:25,代码来源:test_proxy2.py


示例7: bind

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def bind(self, family, type, proto=0):
        """Create (or recreate) the actual socket object."""
        self.socket = socket.socket(family, type, proto)
        prevent_socket_inheritance(self.socket)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if self.nodelay and not isinstance(self.bind_addr, str):
            self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        if self.ssl_adapter is not None:
            self.socket = self.ssl_adapter.bind(self.socket)
        # If listening on the IPV6 any address ('::' = IN6ADDR_ANY),
        # activate dual-stack. See http://www.cherrypy.org/ticket/871.
        if (hasattr(socket, 'AF_INET6') and family == socket.AF_INET6
            and self.bind_addr[0] in ('::', '::0', '::0.0.0.0')):
            try:
                self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
            except (AttributeError, socket.error):
                # Apparently, the socket option is not available in
                # this machine's TCP stack
                pass
        self.socket.bind(self.bind_addr) 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:25,代码来源:__init__.py


示例8: post_build

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def post_build(self, p, pay):
        p += pay
        dataofs = self.dataofs
        if dataofs is None:
            dataofs = 5+((len(self.get_field("options").i2m(self,self.options))+3)/4)
            p = p[:12]+chr((dataofs << 4) | ord(p[12])&0x0f)+p[13:]
        if self.chksum is None:
            if isinstance(self.underlayer, IP):
                if self.underlayer.len is not None:
                    ln = self.underlayer.len-20
                else:
                    ln = len(p)
                psdhdr = struct.pack("!4s4sHH",
                                     inet_aton(self.underlayer.src),
                                     inet_aton(self.underlayer.dst),
                                     self.underlayer.proto,
                                     ln)
                ck=checksum(psdhdr+p)
                p = p[:16]+struct.pack("!H", ck)+p[18:]
            elif conf.ipv6_enabled and isinstance(self.underlayer, scapy.layers.inet6.IPv6) or isinstance(self.underlayer, scapy.layers.inet6._IPv6ExtHdr):
                ck = scapy.layers.inet6.in6_chksum(socket.IPPROTO_TCP, self.underlayer, p)
                p = p[:16]+struct.pack("!H", ck)+p[18:]
            else:
                warning("No IP underlayer to compute checksum. Leaving null.")
        return p 
开发者ID:medbenali,项目名称:CyberScan,代码行数:27,代码来源:inet.py


示例9: init

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def init(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self.socket.connect((self.ms_ip, self.ms_tcp_port))
        self.socket_1 = socket.socket()
        self.recv_handle_live = True
        self.recv_thread = threading.Thread(target=self.recv_handler)
        self.recv_thread.daemon = True
        self.session = Session()
        self.session.conf = {}
        self.session.locks = {}
        self.last_send = 0 
开发者ID:rnbguy,项目名称:pysphere,代码行数:15,代码来源:misphere.py


示例10: setup

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def setup(self):
        self.connection = self.request
        if self.timeout is not None:
            self.connection.settimeout(self.timeout)
        if self.disable_nagle_algorithm:
            self.connection.setsockopt(socket.IPPROTO_TCP,
                                       socket.TCP_NODELAY, True)
        self.rfile = self.connection.makefile('rb', self.rbufsize)
        self.wfile = self.connection.makefile('wb', self.wbufsize) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:11,代码来源:socketserver.py


示例11: set_nodelay

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def set_nodelay(self, value):
        if (self.socket is not None and
                self.socket.family in (socket.AF_INET, socket.AF_INET6)):
            try:
                self.socket.setsockopt(socket.IPPROTO_TCP,
                                       socket.TCP_NODELAY, 1 if value else 0)
            except socket.error as e:
                # Sometimes setsockopt will fail if the socket is closed
                # at the wrong time.  This can happen with HTTPServer
                # resetting the value to false between requests.
                if e.errno != errno.EINVAL and not self._is_connreset(e):
                    raise 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:14,代码来源:iostream.py


示例12: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def __init__(self, source, destination, payload='', proto=socket.IPPROTO_TCP):
        self.version = 4
        self.ihl = 5  # Internet Header Length
        self.tos = 0  # Type of Service
        self.tl = 20 + len(payload)
        self.id = 0  # random.randint(0, 65535)
        self.flags = 0  # Don't fragment
        self.offset = 0
        self.ttl = 64
        self.protocol = proto
        self.checksum = 2  # will be filled by kernel
        self.source = socket.inet_aton(source)
        self.destination = socket.inet_aton(destination) 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:15,代码来源:packet.py


示例13: pack

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def pack(self, source, destination):
        data_offset = (self.offset << 4) + 0
        flags = self.fin + (self.syn << 1) + (self.rst << 2) + (self.psh << 3) + (self.ack << 4) + (self.urg << 5)
        tcp_header = struct.pack('!HHLLBBHHH',
                                 self.srcp,
                                 self.dstp,
                                 self.seqn,
                                 self.ackn,
                                 data_offset,
                                 flags,
                                 self.window,
                                 self.checksum,
                                 self.urgp)
        # pseudo header fields
        source_ip = source
        destination_ip = destination
        reserved = 0
        protocol = socket.IPPROTO_TCP
        total_length = len(tcp_header) + len(self.payload)
        # Pseudo header
        psh = struct.pack("!4s4sBBH",
                          source_ip,
                          destination_ip,
                          reserved,
                          protocol,
                          total_length)
        psh = psh + tcp_header + self.payload
        tcp_checksum = checksum(psh)
        tcp_header = struct.pack("!HHLLBBH",
                                 self.srcp,
                                 self.dstp,
                                 self.seqn,
                                 self.ackn,
                                 data_offset,
                                 flags,
                                 self.window)
        tcp_header += struct.pack('H', tcp_checksum) + struct.pack('!H', self.urgp)
        return tcp_header 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:40,代码来源:packet.py


示例14: get_sockaddr

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def get_sockaddr(host, port, family):
    """Return a fully qualified socket address that can be passed to
    :func:`socket.bind`."""
    if family == af_unix:
        return host.split("://", 1)[1]
    try:
        res = socket.getaddrinfo(
            host, port, family, socket.SOCK_STREAM, socket.IPPROTO_TCP
        )
    except socket.gaierror:
        return host, port
    return res[0][4] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:serving.py


示例15: set_nodelay

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def set_nodelay(sock: socket.socket) -> None:
    """sets the TCP_NODELAY option on the socket (to disable Nagle's algorithm), if possible."""
    with contextlib.suppress(Exception):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) 
开发者ID:irmen,项目名称:Pyro5,代码行数:6,代码来源:socketutil.py


示例16: set_options

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def set_options(self, sock, bound=False):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        return super(TCPSocket, self).set_options(sock, bound=bound) 
开发者ID:jpush,项目名称:jbox,代码行数:5,代码来源:sock.py


示例17: run

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def run(once=False, threads=1, sleep_time_datasets=60, sleep_time_files=60):
    """
    Starts up the consumer threads
    """
    logging.info('resolving brokers')
    brokers_alias = []
    brokers_resolved = []
    try:
        brokers_alias = [b.strip() for b in config_get('tracer-kronos', 'brokers').split(',')]
    except Exception:
        raise Exception('Could not load brokers from configuration')
    logging.info('resolving broker dns alias: %s' % brokers_alias)
    brokers_resolved = []
    for broker in brokers_alias:
        addrinfos = socket.getaddrinfo(broker, 0, socket.AF_INET, 0, socket.IPPROTO_TCP)
        brokers_resolved.extend(ai[4][0] for ai in addrinfos)
    logging.debug('brokers resolved to %s', brokers_resolved)
    dataset_queue = Queue()
    logging.info('starting tracer consumer threads')
    thread_list = []
    for thread in range(0, threads):
        thread_list.append(Thread(target=kronos_file, kwargs={'thread': thread,
                                                              'sleep_time': sleep_time_files,
                                                              'brokers_resolved': brokers_resolved,
                                                              'dataset_queue': dataset_queue}))
        thread_list.append(Thread(target=kronos_dataset, kwargs={'thread': thread,
                                                                 'sleep_time': sleep_time_datasets,
                                                                 'dataset_queue': dataset_queue}))
    [thread.start() for thread in thread_list]
    logging.info('waiting for interrupts')
    while thread_list > 0:
        thread_list = [thread.join(timeout=3) for thread in thread_list if thread and thread.isAlive()] 
开发者ID:rucio,项目名称:rucio,代码行数:43,代码来源:kronos.py


示例18: accept_new_connection

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def accept_new_connection(self, sock):
		try:
			client_sock, addr = sock.accept()
		except (ssl.SSLError, socket.error, OSError):
			return
		client_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
		client = Client(server=self, socket=client_sock)
		self.add_client(client) 
开发者ID:NVDARemote,项目名称:NVDARemote,代码行数:10,代码来源:server.py


示例19: create_outbound_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def create_outbound_socket(self, address):
		address = socket.getaddrinfo(*address)[0]
		server_sock = socket.socket(*address[:3])
		if self.timeout:
			server_sock.settimeout(self.timeout)
		server_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
		server_sock.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 60000, 2000))
		server_sock = ssl.wrap_socket(server_sock)
		return server_sock 
开发者ID:NVDARemote,项目名称:NVDARemote,代码行数:11,代码来源:transport.py


示例20: set_keepalive

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def set_keepalive(sock, after_idle_sec=1, interval_sec=3, max_fails=5):
    """Set TCP keepalive on an open socket.
    It activates after 1 second (after_idle_sec) of idleness,
    then sends a keepalive ping once every 3 seconds (interval_sec),
    and closes the connection after 5 failed ping (max_fails), or 15 seconds
    """
    if hasattr(socket, "SO_KEEPALIVE"):
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    if hasattr(socket, "TCP_KEEPIDLE"):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, after_idle_sec)
    if hasattr(socket, "TCP_KEEPINTVL"):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, interval_sec)
    if hasattr(socket, "TCP_KEEPCNT"):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, max_fails) 
开发者ID:socialwifi,项目名称:RouterOS-api,代码行数:17,代码来源:api_socket.py


示例21: send_request

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def send_request(self, req_inter):
        try:
            if self.logger:
                self.logger.debug("SendRequest %s" % req_inter)
            self.conn.request(req_inter.method, req_inter.uri, req_inter.data, req_inter.header)
            self.conn.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
            try:
                http_resp = self.conn.getresponse()
            except BadStatusLine:
                #open another connection when keep-alive timeout
                #httplib will not handle keep-alive timeout, so we must handle it ourself
                self.conn.close()
                self.conn.request(req_inter.method, req_inter.uri, req_inter.data, req_inter.header)
                self.conn.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
                http_resp = self.conn.getresponse()
            try:
                headers = http_resp.headers
            except:
                headers = dict(http_resp.getheaders())
            resp_inter = ResponseInternal(status = http_resp.status, header = headers, data = http_resp.read())
            self.request_size = self.conn.request_length
            self.response_size = len(resp_inter.data)
            if not self.is_keep_alive():
                self.conn.close()
            if self.logger:
                self.logger.debug("GetResponse %s" % resp_inter)
            return resp_inter
        except Exception as e:
            self.conn.close()
            raise MNSClientNetworkException("NetWorkException", str(e), req_inter.get_req_id()) #raise netException 
开发者ID:gikoluo,项目名称:aliyun-mns,代码行数:33,代码来源:mns_http.py


示例22: _new_conn

# 需要导入模块: import socket [as 别名]
# 或者: from socket import IPPROTO_TCP [as 别名]
def _new_conn(self):
        """ Establish a socket connection and set nodelay settings on it.
        :return: a new socket connection
        """
        extra_args = []
        if self.source_address:  # Python 2.7+
            extra_args.append(self.source_address)
        conn = socket.create_connection(
            (self.host, self.port), self.timeout, *extra_args)
        conn.setsockopt(
            socket.IPPROTO_TCP, socket.TCP_NODELAY, self.tcp_nodelay)
        return conn 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:17,代码来源:connection.py



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