def get_unused_port_and_socket_ipv6():
 s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
 s.bind(('::1', 0))
 (addr, port, flowinfo, scopeid) = s.getsockname()
 return (port, s)

def get_unused_port_and_socket_ipv6 ( ) : s = socket . socket ( socket . AF_INET6 , socket . SOCK_STREAM ) s . bind ( ( '::1' , 0 ) ) ( addr , port , flowinfo , scopeid ) = s . getsockname ( ) return ( port , s )
returns an unused port on localhost and the open socket from which it was created .