Welcome to pyDNS’s documentation!

The DNS module provides DNS lookup functionality. It can operate in a synchronous or asynchronous manner (async not working). The development of pyDNS happens here. The main work horse of this module is the class DnsRequest.

License:This module is covered by the standard Python License.

This page contains the main API overview. More information on specific topics can be found on the following pages:

DNS – DNS lookups

DiscoverNameServers()

Retrieve the system name servers and sets them as default values for the DnsRequest server parameter. This value will be taken as default value for all future DnsRequest instances and as default in DnsRequest.req() if the server parameter is not explicitely given. Calling this once per module lifetime suffices if your DNS servers have not changed in the meanwhile.

Returns:None
dumpQ(u)
FIXME
dumpRR(u)
FIXME

Convenience methods

revlookup(name):

Convenience routine for doing a reverse lookup of an address. This will only return one of any records returned.

Returns:DnsRequest(b, qtype = ‘ptr’).req().answers[0][‘data’]
revlookup6(name):

Takes an IPv6 textual address (rfc 2373 2.2 presentation format (subpart 3, ::i.p.v.4 is explicitly NOT supported).

return q.answers[0][‘data’]

Returns:a name (only one if more than one presented).
mxlookup(name):

Convenience routine for doing an MX lookup of a name.

Returns:List mail exchanger records sorted by preference.

DnsRequest – A DNS request

class DnsRequest(name=''[, server=''][, protocol='udp'][, port=53][, opcode=Opcode.QUERY][, qtype=Type.A][, rd=1][, timing=1][, timout=30])

DnsRequest represents a specific request with a high-level user interface. Call DiscoverNameServers() in order to fill in the default values with the system DNS servers.

Parameters:
  • server (string or list of strings) – DNS server as string or list of strings. You might want to use an IP address here.
  • protocol – ‘udp’ or ‘tcp’
  • port (int) – Port number to query
  • opcode (DNS.Opcode) – query opcode, e.g. QUERY, IQUERY, STATUS, NOTIFY, UPDATE
  • qtype (DNS.Type) – The query type, e.g. SOA, A, MX, CNAME, ANY
  • rd (int) – recursion desired (defaults to 1)
  • timing (int) – FIXME
  • timeout (int) – Timeout of DNS request
Return type:

the initialized DNSRequest instance

req([name=''][, server=[]][, protocol='udp'][, port=53][, opcode=Opcode.QUERY][, qtype=Type.A][, rd=1][, timing=1][, timout=30])

Perform a DNS request.

This method should usually be used to perform DNS requests. Parameters given here, will replace those that have been used to initialize the DnsRequest. All function parameters are identical to the DnsRequest(). Specifying an invalid qtype argument will raise DNSError ‘unknown query type’.

Returns:A DnsResult instance (also bound to the DnsRequest.response attribute) or None (for async calls)
Exception:DNSError in case of errors.

Note

This function would usually be called by the user to perform a DNS query.

sendTCPRequest(server)

Actually perform a TCP Request with the paramters that have previously been set up with the DNSRequest initialization or the parameters passed to req(). This function would usually not be called directly by the user but is invoked from req().

Parameter:server (string or list of strings) – DNS server hostname(s) as string or list of strings
sendUDPRequest(server)

Actually perform a UDP Request with the paramters that have previously been set up with the DNSRequest initialization or the parameters passed to req(). This function would usually not be called directly by the user but is invoked from req().

Parameter:server (string or list of strings) – DNS server hostname(s) as string or list of strings

DnsResult – A DNS request result

class DnsResult(u, args)

An instance of this class is created by the DnsRequest and contains the results of a request.

Parameters:
  • u (FIXME check storeM()) – FIXME (elaborate here). u are passed to storeM().
  • args (FIXME check) – args. FIXME check what this does. Are assigned to DnsResult.args.
show()

Print()s out the DNS reply.

Returns:None
storeM(u)
storeQ(u)
storeRR(u)
Parameter:u (FIXME: a RRunpacker) – FIXME

Returns a dict with the following keys:

  • name
  • type
  • class
  • ttl
  • rdlength
  • typename: Type.typestr() of type
  • classstr: Class.classstr() of class

mname = ‘get%sdata’ % r[‘typename’] if hasattr(u, mname):r[‘data’]=getattr(u, mname)() else:r[‘data’]=u.getbytes(r[‘rdlength’])

Returns:a dict containing the above keys.
storeM(u)
answers
FIXME All answers as a list of whatever storeRR() returns.

DNSError – A DNS request error

exception DNSError
This execption inherits directly from Exception and is raised on errors during the lookup.

Out of date and broken

class DnsAsyncRequest(*name, **args)
an asynchronous request object. out of date, probably broken

Indices and tables