import ipaddress


def get_rev_ptr_name(address, prefix_len) -> str:
    """
    Cuts off the last few blocks of a reverse pointer for an address
    to create a suitable reverse pointer name for a certain prefix length.
    """
    if type(address) is ipaddress.IPv4Address:
        divisor = 8
        address_len = 32
    elif type(address) is ipaddress.IPv6Address:
        divisor = 4
        address_len = 128
    else:
        raise Exception(f"Invalid address type: {address}")

    blocks_to_cut = int(((address_len - prefix_len) / divisor))
    return '.'.join(address.reverse_pointer.split('.')[None:blocks_to_cut])