def isValidHostname(hostname):
 if (len(hostname) > 255):
  return False
 if (hostname[(-1):] == '.'):
  hostname = hostname[:(-1)]
 allowed = re.compile('(?!-)[A-Z\\d-]{1,63}(?<!-)$', re.IGNORECASE)
 return all((allowed.match(x) for x in hostname.split('.')))

def isValidHostname ( hostname ) : if ( len ( hostname ) > 255 ) : return False if ( hostname [ ( - 1 ) : ] == '.' ) : hostname = hostname [ : ( - 1 ) ] allowed = re . compile ( '(?!-)[A-Z\\d-]{1,63}(?<!-)$' , re . IGNORECASE ) return all ( ( allowed . match ( x ) for x in hostname . split ( '.' ) ) )
try to validate the passed host name .