summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/network.py
blob: da4ffda9a99e2da6e903dc28d2ad134a37eb76d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#
# Copyright OpenEmbedded Contributors
#
# SPDX-License-Identifier: MIT
#

import socket

def get_free_port(udp = False):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM if not udp else socket.SOCK_DGRAM)
    s.bind(('', 0))
    addr = s.getsockname()
    s.close()
    return addr[1]