LDNS resolver object.
The ldns_resolver object keeps a list of name servers and can perform queries.
Usage
>>> import ldns
>>> resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
>>> pkt = resolver.query("www.nic.cz", ldns.LDNS_RR_TYPE_A,ldns.LDNS_RR_CLASS_IN)
>>> if (pkt) and (pkt.answer()):
>>> print pkt.answer()
www.nic.cz. 1757 IN A 217.31.205.50
This simple example instances a resolver in order to resolve www.nic.cz A type record.
Returns True if the axfr transfer has completed (i.e., 2 SOA RRs and no errors were encountered).
Returns: | (bool) |
---|
Returns a last packet that was sent by the server in the AXFR transfer (usable for instance to get the error code on failure).
Returns: | (ldns_pkt) Last packet of the AXFR transfer. |
---|
Get the next stream of RRs in a AXFR.
Returns: | (ldns_rr) The next RR from the AXFR stream. |
---|
Prepares the resolver for an axfr query. The query is sent and the answers can be read with axfr_next().
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_status) The status of the transfer. |
Note
The type checking of parameter domain is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.
Usage
status = resolver.axfr_start("nic.cz", ldns.LDNS_RR_CLASS_IN)
if (status != ldns.LDNS_STATUS_OK):
raise Exception("Can't start AXFR, error: %s" % ldns.ldns_get_errorstr_by_id(status))
#Print the results
while True:
rr = resolver.axfr_next()
if not rr:
break
print rr
Get the debug status of the resolver.
Returns: | (bool) True if so, otherwise False. |
---|
Decrement the resolver’s name server count.
Does the resolver apply default domain name.
Returns: | (bool) |
---|
Does the resolver apply search list.
Returns: | (bool) |
---|
Does the resolver do DNSSEC.
Returns: | (bool) True: yes, False: no. |
---|
Get the resolver’s DNSSEC anchors.
Returns: | (ldns_rr_list) An rr list containing trusted DNSSEC anchors. |
---|
Does the resolver set the CD bit.
Returns: | (bool) True: yes, False: no. |
---|
What is the default dname to add to relative queries.
Returns: | (ldns_dname) The dname which is added. |
---|
Get the resolver’s udp size.
Returns: | (uint16_t) The udp mesg size. |
---|
Does the resolver only try the first name server.
Returns: | (bool) True: yes, fail, False: no, try the others. |
---|
Get the truncation fall-back status.
Returns: | (bool) Whether the truncation fall*back mechanism is used. |
---|
Ask the resolver about name and return all address records.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_rr_list) RR List object or None. |
>>> addr = resolver.get_addr_by_name("www.google.com", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD)
>>> if (not addr): raise Exception("Can't retrieve server address")
>>> for rr in addr.rrs():
>>> print rr
www.l.google.com. 300 IN A 74.125.43.99
www.l.google.com. 300 IN A 74.125.43.103
www.l.google.com. 300 IN A 74.125.43.104
www.l.google.com. 300 IN A 74.125.43.147
Ask the resolver about the address and return the name.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_rr_list) RR List object or None. |
>>> addr = resolver.get_name_by_addr("74.125.43.99", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD)
>>> if (not addr): raise Exception("Can't retrieve server address")
>>> for rr in addr.rrs():
>>> print rr
99.43.125.74.in-addr.arpa. 85641 IN PTR bw-in-f99.google.com.
Does the resolver ignore the TC bit (truncated).
Returns: | (bool) True: yes, False: no. |
---|
Increment the resolver’s name server count.
Does the resolver use ip6 or ip4.
Returns: | (uint8_t) 0: both, 1: ip4, 2:ip6 |
---|
How many name server are configured in the resolver.
Returns: | (size_t) Number of name servers. |
---|
Return the used round trip time for a specific name server.
Parameters: | pos (size_t) – The index to the name server. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (size_t) The rrt, 0: infinite, >0: undefined (as of * yet). |
Return the configured name server ip address.
Returns: | (ldns_rdf **) A ldns_rdf pointer to a list of the addresses. |
---|
Randomize the name server list in the resolver.
Creates a new resolver object.
Returns: | (ldns_resolver) New resolver object or None. |
---|
Note
The returned resolver object is unusable unless some name servers are added.
>>> resolver = ldns.ldns_resolver.new()
>>> ns_addr = ldns.ldns_rdf.new_frm_str("8.8.8.8", ldns.LDNS_RDF_TYPE_A)
>>> if not ns_addr: raise Exception("Can't create resolver address.")
>>> status = resolver.push_nameserver(ns_addr)
>>> if status != ldns.LDNS_STATUS_OK: raise Exception("Can't push resolver address.")
>>> pkt = resolver.query("www.nic.cz.", ldns.LDNS_RR_TYPE_A, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD)
>>> if (pkt) and (pkt.answer()):
>>> print pkt.answer()
www.nic.cz. 1265 IN A 217.31.205.50
Creates a resolver object from given file name
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Throws Exception: | |
When raiseException set and resolver couldn’t be created. |
|
Returns: | (ldns_resolver) Resolver object or None. An exception occurs if the object can’t be created and ‘raiseException’ is True. |
Creates a resolver object from file
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Throws Exception: | |
When raiseException set and resolver couldn’t be created. |
|
Returns: | (ldns_resolver) Resolver object or None. An exception occurs if the object can’t be created and raiseException is True. |
Creates a resolver object from file
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Throws Exception: | |
When raiseException set and resolver couldn’t be created. |
|
Returns: |
|
Pop the last name server from the resolver.
Returns: | (ldns_rdf) The popped address or None if empty. |
---|
Get the port the resolver should use.
Returns: | (uint16_t) The port number. |
---|
Form a query packet from a resolver and name/type/class combo.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Throws Exception: | |
When raiseException set and answer couldn’t be resolved. |
|
Returns: | (ldns_pkt) Query packet or None. An exception occurs if the object can’t be created and ‘raiseException’ is True. |
Print a resolver (in so far that is possible) state to output.
Push a new trust anchor to the resolver. It must be a DS or DNSKEY rr.
Parameters: | rr (DS of DNSKEY ldns_rr) – The RR to add as a trust anchor. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (ldns_status) A status. |
Push a new name server to the resolver. It must be an IP address v4 or v6.
Parameters: | n (ldns_rdf of A or AAAA type.) – The ip address. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (ldns_status) A status. |
Push a new name server to the resolver. It must be an A or AAAA RR record type.
Parameters: | rr (ldns_rr of A or AAAA type.) – The resource record. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (ldns_status) A status. |
Push a new name server rr_list to the resolver.
Parameters: | rrlist (ldns_rr_list) – The rr list to push. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (ldns_status) A status. |
Push a new rd to the resolver’s search-list.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Send a query to a name server.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_pkt) A packet with the reply from the name server if _defnames is true the default domain will be added. |
Does the resolver randomize the name server before usage?
Returns: | (bool) True: yes, False: no. |
---|
Is the resolver set to recurse?
Returns: | (bool) True if so, otherwise False. |
---|
Get the retransmit interval.
Returns: | (uint8_t) The retransmit interval. |
---|
Get the number of retries.
Returns: | (uint8_t) The number of retries. |
---|
Return the used round trip times for the name servers.
Returns: | (size_t *) a size_t* pointer to the list. yet) |
---|
Send the query for using the resolver and take the search list into account The search algorithm is as follows: If the name is absolute, try it as-is, otherwise apply the search list.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Returns: | (ldns_pkt) A packet with the reply from the name server. |
What is the search-list as used by the resolver.
Returns: | (ldns_rdf **) A ldns_rdf pointer to a list of the addresses. |
---|
Return the resolver’s search-list count.
Returns: | (size_t) The search-list count. |
---|
Send the query for name as-is.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
|
Throws Exception: | |
When raiseException set and answer couldn’t be resolved. |
|
Returns: | (ldns_pkt) A packet with the reply from the name server. |
Send the given packet to a name server.
Parameters: | query_pkt (ldns_pkt) – Query packet. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: |
|
Set the resolver debugging.
Parameters: | b (bool) – True: debug on, False: debug off. |
---|
Whether the resolver uses the name set with _set_domain.
Parameters: | b (bool) – True: use the defaults, False: don’t use them. |
---|
Whether the resolver uses the search list.
Parameters: | b (bool) – True: use the list, False: don’t use the list. |
---|
Whether the resolver uses DNSSEC.
Parameters: | b (bool) – True: use DNSSEC, False: don’t use DNSSEC. |
---|
Set the resolver’s DNSSEC anchor list directly. RRs should be of type DS or DNSKEY.
Parameters: | l (ldns_rr_list) – The list of RRs to use as trust anchors. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Whether the resolver uses the checking disable bit.
Parameters: | b (bool) – True: enable, False: disable. |
---|
Set the resolver’s default domain. This gets appended when no absolute name is given.
Parameters: | rd (ldns_dname or str) – The name to append. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Throws Exception: | |
When rd a non dname rdf. |
Note
The type checking of parameter rd is benevolent. It allows also to pass a dname ldns_rdf object. This will probably change in future.
Set maximum udp size.
Parameters: | s (uint16_t) – The udp max size. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Whether or not to fail after one failed query.
Parameters: | b (bool) – True: yes fail, False: continue with next name server. |
---|
Set whether the resolvers truncation fall-back mechanism is used when query() is called.
Parameters: | fallback (bool) – Whether to use the fall-back mechanism. |
---|
Whether or not to ignore the TC bit.
Parameters: | b (bool) – True: yes ignore, False: don’t ignore. |
---|
Whether the resolver uses ip6.
Parameters: | i (uint8_t) – 0: no pref, 1: ip4, 2: ip6 |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the resolver’s name server count directly.
Parameters: | c (size_t) – The name server count. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set round trip time for a specific name server. Note this currently differentiates between: unreachable and reachable.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the resolver’s name server count directly by using an rdf list.
Parameters: | rd (ldns_rdf **) – The resolver addresses. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the port the resolver should use.
Parameters: | p (uint16_t) – The port number. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Should the name server list be randomized before each use.
Parameters: | b (bool) – True: randomize, False: don’t. |
---|
Set the resolver recursion.
Parameters: | b (bool) – True: set to recurse, False: unset. |
---|
Set the resolver retrans time-out (in seconds).
Parameters: | re (uint8_t) – The retransmission interval in seconds. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the resolver retry interval (in seconds).
Parameters: | re (uint8_t) – The retry interval. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set round trip time for all name servers. Note this currently differentiates between: unreachable and reachable.
Parameters: | rtt (size *) – A list with the times. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the resolver’s socket time out when talking to remote hosts.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the tsig algorithm.
Parameters: |
|
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the tsig key data.
Parameters: | tsig_keydata (str) – The key data. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Set the tsig key name.
Parameters: | tsig_keyname (str) – The tsig key name. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. |
Whether the resolver uses a virtual circuit (TCP).
Parameters: | b (bool) – True: use TCP, False: don’t use TCP. |
---|
What is the time-out on socket connections.
Returns: | (struct timeval) The time-out. |
---|
Returns true if at least one of the provided keys is a trust anchor.
Parameters: | keys (ldns_rr_list) – The key set to check. |
---|---|
Throws TypeError: | |
When arguments of inappropriate types. | |
Returns: | (ldns_rr_list) List of trusted keys if at least one of the provided keys is a configured trust anchor, None else. |
Return the tsig algorithm as used by the name server.
Returns: | (str) The algorithm used. |
---|
Return the tsig key data as used by the name server.
Returns: | (str) The key data used. |
---|
Return the tsig key name as used by the name server.
Returns: | (str) The name used. |
---|
Does the resolver use tcp or udp.
Returns: | (bool) True: tcp, False: udp. |
---|