dns.client.parse_hosts

dns.client

parse_hosts(path) -> hosts, err

Parse /etc/hosts into a table the resolver answers A and AAAA from

Reads a hosts file and returns a table for the hosts field of dns.client.new(). Each key is a name, lowercased with a trailing dot. Each value holds an A list, an AAAA list, or both, with the addresses in file order and no repeats.

A line's first field is the address and the rest are its names. # starts a comment. A line whose address is neither a dotted quad nor an IPv6 address is skipped, and so is a zoned address such as fe80::1%eth0.

path defaults to "/etc/hosts".

local dns_client = require("dns.client")

local sys = dns_client.parse_resolv_conf()
sys.hosts = dns_client.parse_hosts()
local r = dns_client.new(sys)