dns module
DNS lookups using the OS resolver. Async (callbacks), with helpers for IP-literal detection.
import "dns" as dns;
dns.lookup("example.com", 0, function (err, ip, family) {
if (err != null) { print("lookup failed:", err); return; }
print("got:", ip, "family", family); // got: 93.184.215.14 family 4
});
Lookups
| Function | Description |
|---|---|
dns.lookup(host, family, cb) | cb(err, ip, family) — first matching address. family: 0 = any, 4 = IPv4, 6 = IPv6. |
dns.lookup_all(host, family, cb) | cb(err, [{address, family}, …]) — every match. |
dns.reverse(ip, cb) | cb(err, hostname). Falls back to the IP literal when no PTR record exists. |
Helpers
| Function | Description |
|---|---|
dns.is_ipv4(s) → bool | True if s parses as an IPv4 literal. |
dns.is_ipv6(s) → bool | |
dns.is_ip(s) → bool | is_ipv4 or is_ipv6. |
dns.lookup_or_self(host, cb) | Skip resolution and call back with host if it's already an IP literal. |
See also
net— connect over TCP after resolving.