Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto lookup NAPTR records in Go?

Tags:

go

dns

I am attempting to query NAPTR records in Go. It appears the DNS basics provided in the 'net' library won't give me access. I am therefore looking at using (see docs), but can't find any basic examples. Are there any recommendations on alternatives or some insight on how to query for NAPTR?

like image 857
jsgoecke Avatar asked Dec 22 '13 16:12

jsgoecke


People also ask

What is Naptr DNS record?

¶ NAPTR records, short for Naming Authority Pointer, is a type of record that allows you to set dynamic rules for how your website processes requests. This type of record is especially useful to websites that provide internet telephony services.

Is Naptr the same as PTR?

Answer: No, they are not the same. PTR records are used for Reverse DNS Resolution. And NAPTR records are mostly used for SIP communication.

What is a Naptr SRV query?

The combination of NAPTR records with Service Records (SRV) allows the chaining of multiple records to form complex rewrite rules which produce new domain labels or uniform resource identifiers (URIs). The DNS type code for the NAPTR record is 35.


1 Answers

AFAIK, you would have to roll your own for the net library. Using miekg/dns, I would think something like this:

m := new(dns.Msg)
m.SetQuestion("statdns.net.", dns.TypeNAPTR)
ret, err := dns.Exchange(m, "8.8.8.8:53")

From the ret, you should have an Answer member of []RR. I'm presupposing you can access like:

if t, ok := ret.Answer[0].(*dns.NAPTR); ok {
    // do something with t.Order, t.Preference, etc.
}

The available members are defined in the NAPTR type.

Caveat emptor: I'm away from my workstation for a bit and can't try this out...

like image 116
bishop Avatar answered Sep 21 '22 20:09

bishop