Check that name is DNS subdomain: One or more lowercase rfc1035/rfc1123
    labels separated by '.' with a maximum length of 253 characters
332867
def _is_dns_subdomain(name):
    '''  '''

    dns_subdomain = re.compile(r"""^[a-z0-9\.-]{1,253}$""")
    if dns_subdomain.match(name):
        log.debug("Name: %s is valid DNS subdomain", name)
        return True
    else:
        log.debug("Name: %s is not valid DNS subdomain", name)
        return False
386636
def _get_hostname(self, hostname, metric):
        
        if hostname is None and self.label_to_hostname is not None:
            for label in metric.label:
                if label.name == self.label_to_hostname:
                    return label.value + self.label_to_hostname_suffix

        return hostname
366037
public static function checkDomain($domain_name) {

        if ( $domain_name[0] == '.' ) $domain_name = substr($domain_name, 1);

        return (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $domain_name) //valid chars check
                && preg_match("/^.{1,253}$/", $domain_name) //overall length check
                && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $domain_name)); //length of each label

    }
1104539
def url2domain(url):
    
    parsed_uri = urlparse.urlparse(url)
    domain = '{uri.netloc}'.format(uri=parsed_uri)
    domain = re.sub("^.+@", "", domain)
    domain = re.sub(":.+$", "", domain)
    return domain
426724
def get_subdomain(url):
        

        if url not in URLHelper.__cache:
            URLHelper.__cache[url] = urlparse(url)

        return ".".join(URLHelper.__cache[url].netloc.split(".")[:-2])
597796
def =~(domain)
      labels.zip(domain.labels).all? { |r, d| ["*", d].include? r }
    end
571873
def is_subdomain(self, other):
        

        (nr, o, nl) = self.fullcompare(other)
        if nr == NAMERELN_SUBDOMAIN or nr == NAMERELN_EQUAL:
            return True
        return False
743825
def _sub_hostname(self, line):
        '''
        
        '''
        try:
            for od,d in self.dn_db.items():
                #regex = re.compile(r'\w*\.%s' % d)
                regex = re.compile(r'(?![\W\-\:\ \.])[a-zA-Z0-9\-\_\.]*\.%s' % d)
                hostnames = [each for each in regex.findall(line)]
                if len(hostnames) > 0:
                    for hn in hostnames:
                        new_hn = self._hn2db(hn)
                        self.logger.debug("Obfuscating FQDN - %s > %s", hn, new_hn)
                        line = line.replace(hn, new_hn)
            if self.hostname:
                line = line.replace(self.hostname, self._hn2db(self.hostname))  #catch any non-fqdn instances of the system hostname

            return line
        except Exception as e: # pragma: no cover
            self.logger.exception(e)
            raise Exception('SubHostnameError: Unable to Substitute Hostname/Domainname')
834544
private String toRFC2965HeaderString() {
        StringBuilder sb = new StringBuilder();

        sb.append(getName()).append("=\"").append(getValue()).append('"');
        if (getPath() != null)
            sb.append(";$Path=\"").append(getPath()).append('"');
        if (getDomain() != null)
            sb.append(";$Domain=\"").append(getDomain()).append('"');
        if (getPortlist() != null)
            sb.append(";$Port=\"").append(getPortlist()).append('"');

        return sb.toString();
    }
1064005
def _check(self):
        
        if conf.contribs['LLDP'].strict_mode():
            management_address_len = len(self.management_address)
            if management_address_len == 0 or management_address_len > 31:
                raise LLDPInvalidLengthField(
                    'management address must be  1..31 characters long - '
                    'got string of size {}'.format(management_address_len))
568160
def rpc_get_all_names( self, offset, count, **con_info ):
        
        if not check_offset(offset):
            return {'error': 'invalid offset', 'http_status': 400}

        if not check_count(count, 100):
            return {'error': 'invalid count', 'http_status': 400}

        db = get_db_state(self.working_dir)
        num_domains = db.get_num_names()
        if num_domains > offset:
           all_domains = db.get_all_names( offset=offset, count=count )
        else:
           all_domains = []
        db.close()

        return self.success_response( {'names': all_domains} )
1184632
def subdomain(self, hostname):
        
        hostname = hostname.split(":")[0]
        for domain in getDomainNames(self.siteStore):
            if hostname.endswith("." + domain):
                username = hostname[:-len(domain) - 1]
                if username != "www":
                    return username, domain
        return None
872960
def _dns_weird(self, record):
        """"""
        weird = {}

        # Zero should always be 0
        if record['flags']['zero'] != 0:
            weird['zero'] = record['flags']['zero']

        # Trucated may indicate an exfil
        if record['flags']['truncated']:
            weird['trucnated'] = True

        # Weird Query Types
        weird_types = set(['DNS_NULL', 'DNS_HINFO', 'DNS_TXT', 'UNKNOWN'])
        for query in record['queries']:
            if query['type'] in weird_types:
                weird['query_type'] = query['type']

        # Weird Query Classes
        weird_classes = set(['DNS_CHAOS', 'DNS_HESIOD', 'DNS_NONE', 'DNS_ANY'])
        for query in record['queries']:
            if query['class'] in weird_classes:
                weird['query_class'] = query['class']

        # Weird Answer Types
        for section_name in ['answers', 'name_servers', 'additional']:
            for answer in record['answers'][section_name]:
                if answer['type'] in weird_types:
                    weird['answer_type'] = answer['type']

        # Weird Answer Classes
        for section_name in ['answers', 'name_servers', 'additional']:
            for answer in record['answers'][section_name]:
                if answer['class'] in weird_classes:
                    weird['answer_class'] = answer['class']

        # Is the subdomain name especially long or have high entropy?
        for query in record['queries']:
            subdomain = '.'.join(query['name'].split('.')[:-2])
            length = len(subdomain)
            entropy = self.entropy(subdomain)
            if length > 35 and entropy > 3.5:
                weird['subdomain_length'] = length
                weird['subdomain'] = subdomain
                weird['subdomain_entropy'] = entropy
                weird['subdomain'] = subdomain

        # Return the weird stuff
        return weird
129976
def _extract_from_sans(self):
        """"""
        self.logger.info("{} Trying to find Subdomains in SANs list".format(COLORED_COMBOS.NOTIFY))
        if self.host.naked:
            domain = self.host.naked
            tld_less = domain.split(".")[0]
        else:
            domain = self.host.target.split(".")
            tld_less = domain[1]
            domain = ".".join(domain[1:])

        for san in self.sans:
            if (tld_less in san or domain in san) and self.target != san and not san.startswith("*"):
                self.logger.info("{} Subdomain detected: {}".format(COLORED_COMBOS.GOOD, san))
49582
def privateparts(self, domain):
        
        s = self.privatesuffix(domain)
        if s is None:
            return None
        else:
            # I know the domain is valid and ends with private suffix
            pre = domain[0:-(len(s)+1)]
            if pre == "":
                return (s,)
            else:
                return tuple(pre.split(".") + [s])
611099
def header_name_check(header_name):
		
		header_match = WHTTPHeaders.header_name_re.match(header_name.encode('us-ascii'))
		return len(header_name) > 0 and header_match is not None
309002
def check_dns_txt(domain, prefix, code):
    
    token = '{}={}'.format(prefix, code)
    try:
        for rr in dns.resolver.query(domain, 'TXT'):
            if token in rr.to_text():
                return True
    except:
        logger.debug('', exc_info=True)
    return False