Chapter 5. Helper APIs
This chapter covers a number of APIs that you’ll almost certainly use regularly but aren’t used as much as those discussed in Chapter 4.
DNS
Programmers, like end users, normally want to
refer to things by their domain names instead of their IP addresses. The
DNS module provides this lookup facility to you, but it is also used under
the hood whenever you are able to use a domain name—for example, in
HTTP clients.
The dns
module consists of two main methods and a number of convenience
methods. The two main methods are resolve(), which turns a domain name into a DNS
record, and reverse(), which turns an IP address into a domain. All of the other methods
in the dns module are more specialized
forms of these methods.
dns.resolve() takes three arguments:
- A string containing the domain to be resolved
This can include subdomains, such as
www.yahoo.com. Thewwwis technically a hostname, but the system will resolve it for you.- A string containing the types of records being requested
This requires a little more understanding of DNS. Most people are familiar with the “address” or A record type. This type of record maps an IPv4 domain to a domain name (as defined in the previous item). The “canonical name,” or CNAME, records allow you to create an alias of an A record or another CNAME. For example,
www.example.commight be a CNAME of the A record atexample.com. MX records point to the mail server for a domain for the use of SMTP. When you emailperson@domain.com, the MX record ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access