def dnsrepr2names(x):
 res = []
 cur = ''
 while x:
  l = ord(x[0])
  x = x[1:]
  if (l == 0):
   if (cur and (cur[(-1)] == '.')):
    cur = cur[:(-1)]
   res.append(cur)
   cur = ''
   if (x and (ord(x[0]) == 0)):
    x = x[1:]
   continue
  if (l & 192):
   raise Exception("DNS message can't be compressed at this point!")
  else:
   cur += (x[:l] + '.')
   x = x[l:]
 return res

def dnsrepr2names ( x ) : res = [ ] cur = '' while x : l = ord ( x [ 0 ] ) x = x [ 1 : ] if ( l == 0 ) : if ( cur and ( cur [ ( - 1 ) ] == '.' ) ) : cur = cur [ : ( - 1 ) ] res . append ( cur ) cur = '' if ( x and ( ord ( x [ 0 ] ) == 0 ) ) : x = x [ 1 : ] continue if ( l & 192 ) : raise Exception ( "DNS message can't be compressed at this point!" ) else : cur += ( x [ : l ] + '.' ) x = x [ l : ] return res
take as input a dns encoded string and returns a list of dns names contained in it .