def create_msearch_payload(host, st, mx=1):
    """
    Create an M-SEARCH packet using the given parameters.
    Returns a bytes object containing a valid M-SEARCH request.

    :param host: The address (IP + port) that the M-SEARCH will be sent to. This is usually a multicast address.
    :type host: str

    :param st: Search target. The type of services that should respond to the search.
    :type st: str

    :param mx: Maximum wait time, in seconds, for responses.
    :type mx: int

    :return: A bytes object containing the generated M-SEARCH payload.
    """
    data = (
        "M-SEARCH * HTTP/1.1\r\n"
        "HOST:{}\r\n"
        'MAN: "ssdp:discover"\r\n'
        "ST:{}\r\n"
        "MX:{}\r\n"
        "\r\n"
    ).format(host, st, mx)
    return data.encode("utf-8")