def get_open_port():
 open_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
 open_socket.bind(('', 0))
 port = open_socket.getsockname()[1]
 open_socket.close()
 return port

def get_open_port ( ) : open_socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM , 0 ) open_socket . bind ( ( '' , 0 ) ) port = open_socket . getsockname ( ) [ 1 ] open_socket . close ( ) return port
gets an open port number from the os .