def refusing_port():
 (server_socket, port) = bind_unused_port()
 server_socket.setblocking(1)
 client_socket = socket.socket()
 client_socket.connect(('127.0.0.1', port))
 (conn, client_addr) = server_socket.accept()
 conn.close()
 server_socket.close()
 return (client_socket.close, client_addr[1])

def refusing_port ( ) : ( server_socket , port ) = bind_unused_port ( ) server_socket . setblocking ( 1 ) client_socket = socket . socket ( ) client_socket . connect ( ( '127.0.0.1' , port ) ) ( conn , client_addr ) = server_socket . accept ( ) conn . close ( ) server_socket . close ( ) return ( client_socket . close , client_addr [ 1 ] )
returns a local port number that will refuse all connections .