import binascii


def encode_domain(domain):
    """Given a domain with possible Unicode chars, encode it to hex."""
    try:
        return binascii.hexlify(domain.encode('idna'))
    except UnicodeError:
        # Some strange invalid Unicode domains
        return None