'Check if a domain name or IP address is valid according to the
certificate
:param domain_ip:
A unicode string of a domain name or IP address
:return:
A boolean - if the domain or IP is valid for the certificate'

def is_valid_domain_ip(self, domain_ip):

    if (not isinstance(domain_ip, str_cls)):
        raise TypeError(unwrap(u'\n                                                                domain_ip    must    be    a    unicode    string,    not    %s\n                                                                ', type_name(domain_ip)))
    encoded_domain_ip = domain_ip.encode(u'idna').decode(u'ascii').lower()
    is_ipv6 = (encoded_domain_ip.find(u':') != (-1))
    is_ipv4 = ((not is_ipv6) and re.match(u'^\\d+\\.\\d+\\.\\d+\\.\\d+$', encoded_domain_ip))
    is_domain = ((not is_ipv6) and (not is_ipv4))
    if is_domain:
        if (not self.valid_domains):
            return False
        domain_labels = encoded_domain_ip.split(u'.')
        for valid_domain in self.valid_domains:
            encoded_valid_domain = valid_domain.encode(u'idna').decode(u'ascii').lower()
            valid_domain_labels = encoded_valid_domain.split(u'.')
            if (len(valid_domain_labels) != len(domain_labels)):
                continue
            if (valid_domain_labels == domain_labels):
                return True
            is_wildcard = self._is_wildcard_domain(encoded_valid_domain)
            if (is_wildcard and self._is_wildcard_match(domain_labels, valid_domain_labels)):
                return True
        return False
    if (not self.valid_ips):
        return False
    family = (socket.AF_INET if is_ipv4 else socket.AF_INET6)
    normalized_ip = inet_pton(family, encoded_domain_ip)
    for valid_ip in self.valid_ips:
        valid_family = (socket.AF_INET if (valid_ip.find(u'.') != (-1)) else socket.AF_INET6)
        normalized_valid_ip = inet_pton(valid_family, valid_ip)
        if (normalized_valid_ip == normalized_ip):
            return True
    return False
