Example #1
0
 def testResponseToAscii(self):
     ns = mocks.MockNameServer(mocks.GOOD_IP)
     (response, duration,
      exception) = ns.TimedRequest('A', 'www.paypal.com')
     self.assertEquals(nameserver.ResponseToAscii(response),
                       '66.211.169.65 + 66.211.169.2')
     response.answer = None
     self.assertEquals(nameserver.ResponseToAscii(response), 'no answer')
Example #2
0
 def _GenerateIndexSummary(self, ns):
     # Get the meat out of the index data.
     index = []
     if ns in self.index:
         for host, req_type, duration, response, unused_x in self.index[ns]:
             answer_count, ttl = self._ResponseToCountTtlText(response)[0:2]
             index.append((host, req_type, duration, answer_count, ttl,
                           nameserver.ResponseToAscii(response)))
     return index
Example #3
0
    def _ResponseToCountTtlText(self, response):
        """For a given DNS response, parse the most important details out.

    Args:
      response: DNS response

    Returns:
      tuple of (answer_count, ttl, answer_text)
    """

        answer_text = ''
        answer_count = -1
        ttl = -1
        if response:
            if response.answer:
                answer_count = len(response.answer)
                ttl = response.answer[0].ttl
            answer_text = nameserver.ResponseToAscii(response)
        return (answer_count, ttl, answer_text)