1# 2# Copyright OpenEmbedded Contributors 3# 4# SPDX-License-Identifier: MIT 5# 6 7import socket 8 9def get_free_port(udp = False): 10 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM if not udp else socket.SOCK_DGRAM) 11 s.bind(('', 0)) 12 addr = s.getsockname() 13 s.close() 14 return addr[1] 15