Python socket.SOL_TCP Examples
The following are 30
code examples of socket.SOL_TCP().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
socket
, or try the search function
.
Example #1
Source File: test_functional.py From oss-ftp with MIT License | 6 votes |
def test_tcp_no_delay(self): def get_handler_socket(): # return the server's handler socket object ioloop = IOLoop.instance() for fd in ioloop.socket_map: instance = ioloop.socket_map[fd] if isinstance(instance, FTPHandler): break return instance.socket s = get_handler_socket() self.assertTrue(s.getsockopt(socket.SOL_TCP, socket.TCP_NODELAY)) self.client.quit() self.server.handler.tcp_no_delay = False self.client.connect(self.server.host, self.server.port) self.client.sendcmd('noop') s = get_handler_socket() self.assertFalse(s.getsockopt(socket.SOL_TCP, socket.TCP_NODELAY))
Example #2
Source File: udprelay.py From ssr-ml with Apache License 2.0 | 6 votes |
def _create_remote_socket(self, ip, port): addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) if len(addrs) == 0: raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) af, socktype, proto, canonname, sa = addrs[0] if self._forbidden_iplist: if common.to_str(sa[0]) in self._forbidden_iplist: raise Exception('IP %s is in forbidden list, reject' % common.to_str(sa[0])) remote_sock = socket.socket(af, socktype, proto) self._remote_sock = remote_sock self._fd_to_handlers[remote_sock.fileno()] = self remote_sock.setblocking(False) remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) return remote_sock
Example #3
Source File: udprelay.py From shadowsocksr with Apache License 2.0 | 6 votes |
def _create_remote_socket(self, ip, port): addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) if len(addrs) == 0: raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) af, socktype, proto, canonname, sa = addrs[0] if self._forbidden_iplist: if common.to_str(sa[0]) in self._forbidden_iplist: raise Exception('IP %s is in forbidden list, reject' % common.to_str(sa[0])) remote_sock = socket.socket(af, socktype, proto) self._remote_sock = remote_sock self._fd_to_handlers[remote_sock.fileno()] = self remote_sock.setblocking(False) remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) return remote_sock
Example #4
Source File: resolver.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def _gethostbyaddr(ip): try: addr = dns.ipv6.inet_aton(ip) sockaddr = (ip, 80, 0, 0) family = socket.AF_INET6 except: sockaddr = (ip, 80) family = socket.AF_INET (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD) aliases = [] addresses = [] tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP, socket.AI_CANONNAME) canonical = tuples[0][3] for item in tuples: addresses.append(item[4][0]) # XXX we just ignore aliases return (canonical, aliases, addresses)
Example #5
Source File: _http.py From launcher with GNU General Public License v3.0 | 6 votes |
def _get_addrinfo_list(hostname, port, is_secure, proxy): phost, pport, pauth = get_proxy_info( hostname, is_secure, proxy.host, proxy.port, proxy.auth, proxy.no_proxy) try: if not phost: addrinfo_list = socket.getaddrinfo( hostname, port, 0, 0, socket.SOL_TCP) return addrinfo_list, False, None else: pport = pport and pport or 80 # when running on windows 10, the getaddrinfo used above # returns a socktype 0. This generates an error exception: #_on_error: exception Socket type must be stream or datagram, not 0 # Force the socket type to SOCK_STREAM addrinfo_list = socket.getaddrinfo(phost, pport, 0, socket.SOCK_STREAM, socket.SOL_TCP) return addrinfo_list, True, pauth except socket.gaierror as e: raise WebSocketAddressException(e)
Example #6
Source File: test_connection.py From aredis with MIT License | 6 votes |
def test_connect_tcp_keepalive_options(event_loop): conn = Connection( loop=event_loop, socket_keepalive=True, socket_keepalive_options={ socket.TCP_KEEPIDLE: 1, socket.TCP_KEEPINTVL: 1, socket.TCP_KEEPCNT: 3, }, ) await conn._connect() sock = conn._writer.transport.get_extra_info('socket') assert sock.getsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE) == 1 for k, v in ( (socket.TCP_KEEPIDLE, 1), (socket.TCP_KEEPINTVL, 1), (socket.TCP_KEEPCNT, 3), ): assert sock.getsockopt(socket.SOL_TCP, k) == v conn.disconnect()
Example #7
Source File: SocketWrapper.py From ufora with Apache License 2.0 | 6 votes |
def __init__(self, inSock, nodelay = True, littleEndian = True): self.prefix_ = "" if littleEndian else ">" self.sock_ = inSock self.sock_.setblocking(0) if nodelay: self.sock_.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0) self.readTime = .001 self.gotSize_ = False self.msgSize_ = 0 self.buf_ = "" self.gotSize_ = False self.incoming = collections.deque() self.outgoing = collections.deque() # element access functions
Example #8
Source File: tcprelay.py From shadowsocks with Apache License 2.0 | 6 votes |
def _create_remote_socket(self, ip, port): addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) if len(addrs) == 0: raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) af, socktype, proto, canonname, sa = addrs[0] if self._forbidden_iplist: if common.to_str(sa[0]) in self._forbidden_iplist: raise Exception('IP %s is in forbidden list, reject' % common.to_str(sa[0])) remote_sock = socket.socket(af, socktype, proto) self._remote_sock = remote_sock self._fd_to_handlers[remote_sock.fileno()] = self remote_sock.setblocking(False) remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) return remote_sock
Example #9
Source File: tcprelay.py From shadowsocks with Apache License 2.0 | 6 votes |
def _socket_bind_addr(self, sock, af): bind_addr = '' if self._bind and af == socket.AF_INET: bind_addr = self._bind elif self._bindv6 and af == socket.AF_INET6: bind_addr = self._bindv6 else: bind_addr = self._accept_address[0] bind_addr = bind_addr.replace("::ffff:", "") if bind_addr in self._ignore_bind_list: bind_addr = None if self._is_relay: bind_addr = None if bind_addr: local_addrs = socket.getaddrinfo( bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP) if local_addrs[0][0] == af: logging.debug("bind %s" % (bind_addr,)) sock.bind((bind_addr, 0))
Example #10
Source File: _http.py From deepWordBug with Apache License 2.0 | 6 votes |
def _get_addrinfo_list(hostname, port, is_secure, proxy): phost, pport, pauth = get_proxy_info( hostname, is_secure, proxy.host, proxy.port, proxy.auth, proxy.no_proxy) try: if not phost: addrinfo_list = socket.getaddrinfo( hostname, port, 0, 0, socket.SOL_TCP) return addrinfo_list, False, None else: pport = pport and pport or 80 # when running on windows 10, the getaddrinfo used above # returns a socktype 0. This generates an error exception: #_on_error: exception Socket type must be stream or datagram, not 0 # Force the socket type to SOCK_STREAM addrinfo_list = socket.getaddrinfo(phost, pport, 0, socket.SOCK_STREAM, socket.SOL_TCP) return addrinfo_list, True, pauth except socket.gaierror as e: raise WebSocketAddressException(e)
Example #11
Source File: tcprelay.py From ShadowsocksFork with Apache License 2.0 | 6 votes |
def _create_remote_socket(self, ip, port): addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) if len(addrs) == 0: raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) af, socktype, proto, canonname, sa = addrs[0] if self._forbidden_iplist: if common.to_str(sa[0]) in self._forbidden_iplist: raise Exception('IP %s is in forbidden list, reject' % common.to_str(sa[0])) remote_sock = socket.socket(af, socktype, proto) self._remote_sock = remote_sock self._fd_to_handlers[remote_sock.fileno()] = self remote_sock.setblocking(False) remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) return remote_sock
Example #12
Source File: tcprelay.py From Dockerfiles with Apache License 2.0 | 6 votes |
def _socket_bind_addr(self, sock, af): bind_addr = '' if self._bind and af == socket.AF_INET: bind_addr = self._bind elif self._bindv6 and af == socket.AF_INET6: bind_addr = self._bindv6 else: bind_addr = self._accept_address[0] bind_addr = bind_addr.replace("::ffff:", "") if bind_addr in self._ignore_bind_list: bind_addr = None if bind_addr: local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP) if local_addrs[0][0] == af: logging.debug("bind %s" % (bind_addr,)) try: sock.bind((bind_addr, 0)) except Exception as e: logging.warn("bind %s fail" % (bind_addr,))
Example #13
Source File: test_functional.py From oss-ftp with MIT License | 6 votes |
def test_tcp_no_delay(self): def get_handler_socket(): # return the server's handler socket object ioloop = IOLoop.instance() for fd in ioloop.socket_map: instance = ioloop.socket_map[fd] if isinstance(instance, FTPHandler): break return instance.socket s = get_handler_socket() self.assertTrue(s.getsockopt(socket.SOL_TCP, socket.TCP_NODELAY)) self.client.quit() self.server.handler.tcp_no_delay = False self.client.connect(self.server.host, self.server.port) self.client.sendcmd('noop') s = get_handler_socket() self.assertFalse(s.getsockopt(socket.SOL_TCP, socket.TCP_NODELAY))
Example #14
Source File: models.py From fermentrack with MIT License | 6 votes |
def open_socket(self): if self.useInetSocket: this_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.SOL_TCP) else: this_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) if this_socket: try: if self.useInetSocket: this_socket.connect((self.socketHost, self.socketPort)) else: this_socket.connect(self.socket_name) except: this_socket.close() return this_socket
Example #15
Source File: tcprelay.py From shadowsocksR-b with Apache License 2.0 | 6 votes |
def _socket_bind_addr(self, sock, af): bind_addr = '' if self._bind and af == socket.AF_INET: bind_addr = self._bind elif self._bindv6 and af == socket.AF_INET6: bind_addr = self._bindv6 else: bind_addr = self._accept_address[0] bind_addr = bind_addr.replace("::ffff:", "") if bind_addr in self._ignore_bind_list: bind_addr = None if bind_addr: local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP) if local_addrs[0][0] == af: logging.debug("bind %s" % (bind_addr,)) try: sock.bind((bind_addr, 0)) except Exception as e: logging.warn("bind %s fail" % (bind_addr,))
Example #16
Source File: tcprelay.py From SSRSpeed with GNU General Public License v3.0 | 6 votes |
def _socket_bind_addr(self, sock, af): bind_addr = '' if self._bind and af == socket.AF_INET: bind_addr = self._bind elif self._bindv6 and af == socket.AF_INET6: bind_addr = self._bindv6 else: bind_addr = self._accept_address[0] bind_addr = bind_addr.replace("::ffff:", "") if bind_addr in self._ignore_bind_list: bind_addr = None if bind_addr: local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP) if local_addrs[0][0] == af: logging.debug("bind %s" % (bind_addr,)) try: sock.bind((bind_addr, 0)) except Exception as e: logging.warn("bind %s fail" % (bind_addr,))
Example #17
Source File: _http.py From vnpy_crypto with MIT License | 6 votes |
def _get_addrinfo_list(hostname, port, is_secure, proxy): phost, pport, pauth = get_proxy_info( hostname, is_secure, proxy.host, proxy.port, proxy.auth, proxy.no_proxy) try: if not phost: addrinfo_list = socket.getaddrinfo( hostname, port, 0, 0, socket.SOL_TCP) return addrinfo_list, False, None else: pport = pport and pport or 80 # when running on windows 10, the getaddrinfo used above # returns a socktype 0. This generates an error exception: #_on_error: exception Socket type must be stream or datagram, not 0 # Force the socket type to SOCK_STREAM addrinfo_list = socket.getaddrinfo(phost, pport, 0, socket.SOCK_STREAM, socket.SOL_TCP) return addrinfo_list, True, pauth except socket.gaierror as e: raise WebSocketAddressException(e)
Example #18
Source File: udprelay.py From shadowsocks with Apache License 2.0 | 6 votes |
def _socket_bind_addr(self, sock, af, is_relay): bind_addr = '' if self._bind and af == socket.AF_INET: bind_addr = self._bind elif self._bindv6 and af == socket.AF_INET6: bind_addr = self._bindv6 bind_addr = bind_addr.replace("::ffff:", "") if bind_addr in self._ignore_bind_list: bind_addr = None if is_relay: bind_addr = None if bind_addr: local_addrs = socket.getaddrinfo( bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP) if local_addrs[0][0] == af: logging.debug("bind %s" % (bind_addr,)) sock.bind((bind_addr, 0))
Example #19
Source File: resolver.py From script.elementum.burst with Do What The F*ck You Want To Public License | 6 votes |
def _gethostbyaddr(ip): try: dns.ipv6.inet_aton(ip) sockaddr = (ip, 80, 0, 0) family = socket.AF_INET6 except Exception: sockaddr = (ip, 80) family = socket.AF_INET (name, port) = _getnameinfo(sockaddr, socket.NI_NAMEREQD) aliases = [] addresses = [] tuples = _getaddrinfo(name, 0, family, socket.SOCK_STREAM, socket.SOL_TCP, socket.AI_CANONNAME) canonical = tuples[0][3] for item in tuples: addresses.append(item[4][0]) # XXX we just ignore aliases return (canonical, aliases, addresses)
Example #20
Source File: tcprelay.py From neverendshadowsocks with Apache License 2.0 | 6 votes |
def _create_remote_socket(self, ip, port): addrs = socket.getaddrinfo(ip, port, 0, socket.SOCK_STREAM, socket.SOL_TCP) if len(addrs) == 0: raise Exception("getaddrinfo failed for %s:%d" % (ip, port)) af, socktype, proto, canonname, sa = addrs[0] if self._forbidden_iplist: if common.to_str(sa[0]) in self._forbidden_iplist: raise Exception('IP %s is in forbidden list, reject' % common.to_str(sa[0])) remote_sock = socket.socket(af, socktype, proto) self._remote_sock = remote_sock self._fd_to_handlers[remote_sock.fileno()] = self remote_sock.setblocking(False) remote_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) return remote_sock
Example #21
Source File: tcprelay.py From ssrr with Apache License 2.0 | 6 votes |
def _socket_bind_addr(self, sock, af): bind_addr = '' if self._bind and af == socket.AF_INET: bind_addr = self._bind elif self._bindv6 and af == socket.AF_INET6: bind_addr = self._bindv6 else: bind_addr = self._accept_address[0] bind_addr = bind_addr.replace("::ffff:", "") if bind_addr in self._ignore_bind_list: bind_addr = None if bind_addr: local_addrs = socket.getaddrinfo(bind_addr, 0, 0, socket.SOCK_STREAM, socket.SOL_TCP) if local_addrs[0][0] == af: logging.debug("bind %s" % (bind_addr,)) try: sock.bind((bind_addr, 0)) except Exception as e: logging.warn("bind %s fail" % (bind_addr,))
Example #22
Source File: server.py From OpenNFB with GNU General Public License v3.0 | 6 votes |
def init(self, channels): global main_socket if not main_socket: main_socket = socket.socket() main_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Disable Nagle's algorithm main_socket.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) main_socket.bind(('', 2666)) main_socket.listen(1) self.channels = list(channels.values()) threading.Thread(target=self.socket_thread).start() # Add header and send to clients
Example #23
Source File: _http.py From ChromeREPL with MIT License | 5 votes |
def _get_addrinfo_list(hostname, port, is_secure, proxy): phost, pport, pauth = get_proxy_info( hostname, is_secure, proxy.host, proxy.port, proxy.auth, proxy.no_proxy) try: if not phost: addrinfo_list = socket.getaddrinfo( hostname, port, 0, 0, socket.SOL_TCP) return addrinfo_list, False, None else: pport = pport and pport or 80 addrinfo_list = socket.getaddrinfo(phost, pport, 0, 0, socket.SOL_TCP) return addrinfo_list, True, pauth except socket.gaierror as e: raise WebSocketAddressException(e)
Example #24
Source File: serving.py From planespotter with MIT License | 5 votes |
def get_sockaddr(host, port, family): """Returns a fully qualified socket address, that can properly used by socket.bind""" try: res = socket.getaddrinfo(host, port, family, socket.SOCK_STREAM, socket.SOL_TCP) except socket.gaierror: return (host, port) return res[0][4]
Example #25
Source File: tcprelay.py From shadowsocks with Apache License 2.0 | 5 votes |
def __init__(self, server, fd_to_handlers, loop, local_sock, config, dns_resolver, is_local): self._server = server self._fd_to_handlers = fd_to_handlers self._loop = loop self._local_sock = local_sock self._remote_sock = None self._config = config self._dns_resolver = dns_resolver # TCP Relay works as either sslocal or ssserver # if is_local, this is sslocal self._is_local = is_local self._stage = STAGE_INIT self._encryptor = encrypt.Encryptor(config['password'], config['method']) self._fastopen_connected = False self._data_to_write_to_local = [] self._data_to_write_to_remote = [] self._upstream_status = WAIT_STATUS_READING self._downstream_status = WAIT_STATUS_INIT self._client_address = local_sock.getpeername()[:2] self._remote_address = None if 'forbidden_ip' in config: self._forbidden_iplist = config['forbidden_ip'] else: self._forbidden_iplist = None if is_local: self._chosen_server = self._get_a_server() fd_to_handlers[local_sock.fileno()] = self local_sock.setblocking(False) local_sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) loop.add(local_sock, eventloop.POLL_IN | eventloop.POLL_ERR, self._server) self.last_activity = 0 self._update_activity()
Example #26
Source File: tcprelay.py From ssr-ml with Apache License 2.0 | 5 votes |
def _get_redirect_host(self, client_address, ogn_data): host_list = self._redir_list or ["0.0.0.0:0"] hash_code = binascii.crc32(ogn_data) addrs = socket.getaddrinfo(client_address[0], client_address[1], 0, socket.SOCK_STREAM, socket.SOL_TCP) af, socktype, proto, canonname, sa = addrs[0] address_bytes = common.inet_pton(af, sa[0]) if af == socket.AF_INET6: addr = struct.unpack('>Q', address_bytes[8:])[0] elif af == socket.AF_INET: addr = struct.unpack('>I', address_bytes)[0] else: addr = 0 host_port = [] match_port = False if type(host_list) != list: host_list = [host_list] for host in host_list: items = common.to_str(host).rsplit(':', 1) if len(items) > 1: try: port = int(items[1]) if port == self._server._listen_port: match_port = True host_port.append((items[0], port)) except: pass else: host_port.append((host, 80)) if match_port: last_host_port = host_port host_port = [] for host in last_host_port: if host[1] == self._server._listen_port: host_port.append(host) return host_port[((hash_code & 0xffffffff) + addr) % len(host_port)]
Example #27
Source File: tcpbanner.py From opencanary with BSD 3-Clause "New" or "Revised" License | 5 votes |
def connectionMade(self): #We limit the data sent through to 255 chars data = str(self.accept_banner)[:255] logdata = {'FUNCTION': 'CONNECTION_MADE', 'DATA':data, 'BANNER_ID':str(self.banner_id)} if self.keep_alive_enabled: if hasattr(socket, 'TCP_KEEPIDLE'): # overrides value (in seconds) of system-wide ipv4 tcp_keepalive_time self.transport.getHandle().setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, self.keep_alive_idle) # overrides value (in seconds) of system-wide ipv4 tcp_keepalive_intvl self.transport.getHandle().setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, self.keep_alive_interval) # overrides value (in seconds) of system-wide ipv4 tcp_keepalive_probes self.transport.getHandle().setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT, self.keep_alive_probes) # set keep alive on socket self.transport.setTcpKeepAlive(1) self.factory.canaryservice.logtype = self.factory.canaryservice.logger.LOG_TCP_BANNER_KEEP_ALIVE_CONNECTION_MADE self.factory.canaryservice.log(logdata, transport=self.transport) elif not self.alert_string_enabled: #flag says we need to wait for incoming data to include a string #so no point in logging anything here self.factory.canaryservice.logtype = self.factory.canaryservice.logger.LOG_TCP_BANNER_CONNECTION_MADE self.factory.canaryservice.log(logdata, transport=self.transport) self.transport.write(self.accept_banner)
Example #28
Source File: tcprelay.py From shadowsocksR-b with Apache License 2.0 | 5 votes |
def _update_tcp_mss(self, local_sock): self._tcp_mss = TCP_MSS try: tcp_mss = local_sock.getsockopt(socket.SOL_TCP, socket.TCP_MAXSEG) if tcp_mss > 500 and tcp_mss <= 1500: self._tcp_mss = tcp_mss logging.debug("TCP MSS = %d" % (self._tcp_mss,)) except: pass
Example #29
Source File: server.py From yugioh-game with MIT License | 5 votes |
def on_connect(self, caller): ### for backwards compatibility ### caller.connection._ = lambda s: caller.connection.player._(s) caller.connection.player = None caller.connection.session = self.session_factory() caller.connection.web = False caller.connection.dont_process = False caller.connection.transport.setTcpKeepAlive(True) if hasattr(socket, "TCP_KEEPIDLE"): caller.connection.transport.socket.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 120)
Example #30
Source File: rawwebsocket.py From AstroBox with GNU Affero General Public License v3.0 | 5 votes |
def open(self): # Stats self.server.stats.on_conn_opened() # Disable nagle if needed if self.server.settings['disable_nagle']: self.stream.socket.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1) # Create and attach to session self.session = RawSession(self.server.get_connection_class(), self.server) self.session.set_handler(self) self.session.verify_state()