import socket


def open_udp_port(bindaddr, min, max):
    """
      Try to open a UDP listening port in the given range
    """
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    for port in range(min, max + 1):
        try:
            sock.bind((bindaddr, port))
            return sock, port
        except:
            pass

    sock.close()
    return None, None