Package tlslite :: Package utils :: Module dns_utils
[hide private]
[frames] | no frames]

Source Code for Module tlslite.utils.dns_utils

 1  import re 
 2   
3 -def is_valid_hostname(hostname):
4 if hostname[-1] == ".": 5 # strip exactly one dot from the right, if present 6 hostname = hostname[:-1] 7 if len(hostname) > 253: 8 return False 9 10 # must not be all-numeric, so that it can't be confused with an ip-address 11 if re.match(r"[\d.]+$", hostname): 12 return False 13 14 allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE) 15 return all(allowed.match(x) for x in hostname.split("."))
16