Logo Search packages:      
Sourcecode: namebench version File versions  Download package

def libnamebench::nameserver::NameServer::TimedRequest (   self,
  type_string,
  record_string,
  timeout = None 
)

Make a DNS request, returning the reply and duration it took.

Args:
  type_string: DNS record type to query (string)
  record_string: DNS record name to query (string)
  timeout: optional timeout (float)

Returns:
  A tuple of (response, duration in ms [float], error_msg)

In the case of a DNS response timeout, the response object will be None.

Definition at line 179 of file nameserver.py.

00179                                                                   :
    """Make a DNS request, returning the reply and duration it took.

    Args:
      type_string: DNS record type to query (string)
      record_string: DNS record name to query (string)
      timeout: optional timeout (float)

    Returns:
      A tuple of (response, duration in ms [float], error_msg)

    In the case of a DNS response timeout, the response object will be None.
    """
    request_type = dns.rdatatype.from_text(type_string)
    record = dns.name.from_text(record_string, None)
    request = None
    self.request_count += 1

    # Sometimes it takes great effort just to craft a UDP packet.
    try:
      request = self.CreateRequest(record, request_type, dns.rdataclass.IN)
    except ValueError, exc:
      if not request:
        return (None, 0, util.GetLastExceptionString())

    if not timeout:
      timeout = self.timeout

    error_msg = None
    exc = None
    duration = None
    try:
      start_time = self.timer()
      response = self.Query(request, timeout)
      duration = self.timer() - start_time
    except (dns.exception.Timeout), exc:
      response = None
    except (dns.query.BadResponse, dns.message.TrailingJunk,
            dns.query.UnexpectedSource), exc:
      response = None
    except (socket.error):
      response = None
      if ':' in self.ip:
        error_msg = 'socket error: IPv6 may not be available.'
    # Pass these up the food chain
    except (KeyboardInterrupt, SystemExit, SystemError), exc:
      raise exc
    except:
      error_msg = util.GetLastExceptionString()
      print "* Unusual error with %s:%s on %s: %s" % (type_string, record_string, self, error_msg)
      response = None

    if not response:
      self.error_count += 1

    if not duration:
      duration = self.timer() - start_time

    if exc and not error_msg:
      error_msg = '%s: %s' % (record_string, util.GetLastExceptionString())

#    if error_msg:
#      print '%s will report: %s' % (self, error_msg)

    return (response, util.SecondsToMilliseconds(duration), error_msg)

  def ResponseToAscii(self, response):


Generated by  Doxygen 1.6.0   Back to index