str = dig(name[,type[,server]])
The dig() function performs a similar service to the like-named program, the Domain Information Groper (DIG), provided with the Berkely Internet Name Deamon (BIND), the most widely used DNS server on the Internet. It supplies a UDP interface to any name server and can be readily used by programmers with sufficient understanding of the DNS protocols.
This function assumes a class of IN (Internet), while "name" is required and specifies the "fully qualified domain name" (FQDN) of the Internet domain of interest. The (optional) type argument is a string containing the any-cased name of the resource records (RR) to be retrieved (e.g. "A", "AAAA" or "ptr"). If omitted, "*" is assumed and specifies all RR types. The optional server argument specifies the IP4 or IP6 address of the DNS server to be queried. If omitted, this defaults to 127.0.0.1 (i.e. the local host).
On success, dig() returns a single string containing exactly one header line, followed by zero or more "resource record" (RR) lines, separated by "\u0700" characters. This allows any 8-bit bytes to be retrieved from the RDATA (including embedded \0 and \n characters). The easy to remember \u0700 is the Syriac end-of-paragraph character (which displays as four dots in a "cross" pattern). Note that internationalized domain names are not converted to Unicode.
The (first) header line contains a space-separated list of upper-cased tokens, beginning with the DNS server's response code (NOERROR, SERVFAIL, NXDOMAIN, etc.). This is followed by various flags (AA, RA, etc.) and, finally, the server's declared maximum buffer size: MAXBUF(n).
The RR lines contain a space-separated list of elements from each DNS record. The "section" name is first (query, reply, dnsoa or extra), followed by TTL, DNS name, RR type (cname, a, aaaa, ptr, etc.). The record's optional RDATA appears last and might contain embedded spaces. (Typically, it will be the target IP address or another, canonical, DNS name).
Any valid response from a server is considered "success" and the result string is returned (even for NXDOMAIN). Only if there is an underlying system or transport problem is a null returned, with errno set appropriately.