This function looks up the domain name name. The type argument specifies type of the query to perform. On success, the function returns DNS reply descriptor, a non-negative integer number identifying the reply. It can then be passed to any of the ‘dns_reply_’ functions discussed below in order to retrieve the information from it.
If no matching records were found, the function returns ‘-1’.
On error, it throws a corresponding exception.
The type argument is one of the following constants (defined in the module ‘dns’):
Query the ‘A’ record. The domain should be the hostname to look up.
Query the ‘NS’ records.
Query the ‘PTR’ record. The domain address should be the IP address in dotted-quad form.
Query the ‘MX’ records.
Query the ‘TXT’ records.
If the query returns multiple RR sets, the optional argument sort controls whether they should be returned in the same order as obtained from the DNS (0, the default), or should be sorted (1).
The optional argument resolve is consulted for type
DNS_TYPE_MX
and DNS_TYPE_NS
. If it is 1, the
DNS_TYPE_MX
query will return host names of the MX servers (by
default, it returns IP addresses) and the DNS_TYPE_NS
query
will return IP addresses of the name servers (by default it returns
hostnames).
To extract actual data from the dns_query
return value, use the
functions dns_reply_count
and dns_reply_string
. The
usual processing sequence is:
require dns # Send the query and save the reply descriptor set n dns_query(DNS_TYPE_NS, domain_name) if n >= 0 # If non-empty set is returned, iterate over each value in it: loop for set i 0, while i < dns_reply_count(n), set i i + 1 do # Get the actual data: echo dns_reply_string(n, i) done # Release the memory associated with the reply. dns_reply_release(n) fi
Release the memory associated with the reply rd. If rd is -1, the function does nothing.
Return the number of records in the reply rd. For convenience, if rd is -1, the function returns 0. If rd is negative (excepting -1), a ‘e_failure’ exception is thrown.
Returns nth record from the DNS reply rd.
Returns nth record from the DNS reply rd, if the reply contains IP addresses.
This document was generated on August 13, 2022 using makeinfo.
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.