nim-ndns
nim-ndns copied to clipboard
How do I get CNAME record?
As I understand, I can only fetch A, AAAA and RDNS records. Is there a way to get CNAME records? i.e. through dnsQuery function?
Types of queries that do not have their own procedure can be made using procedures dnsAsyncQuery and dnsQuery or dnsAsyncTcpQuery and dnsTcpQuery. To see the types of queries currently supported, see the dnsprotocol package.
Here is a basic example using what is in the readme:
import ndns
let
header = initHeader(randId(), rd = true)
question = initQuestion("irc.vircio.org", QType.CNAME, QClass.IN)
msg = initMessage(header, @[question])
client = initDnsClient()
rmsg = dnsQuery(client, msg)
if rmsg.header.flags.rcode == RCode.NoError:
for rr in rmsg.answers:
if rr.name != msg.questions[0].qname or rr.`type` != Type.CNAME or
rr.class != Class.IN: continue
echo "Canonical name: ", cast[RDataCNAME](rr.rdata).cname
This should return: Canonical name: irc.vircio.net.