英文:
Howto lookup NAPTR records in Go?
问题
我正在尝试在Go语言中查询NAPTR
记录。看起来net
库提供的DNS
基础知识无法满足我的需求。因此,我正在考虑使用(参见文档),但是找不到任何基本示例。是否有关于替代方案的建议,或者关于如何查询NAPTR
记录的一些见解?
英文:
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
?
答案1
得分: 5
根据我的理解,你需要为网络库自己编写代码。使用miekg/dns库,你可以尝试以下代码:
m := new(dns.Msg)
m.SetQuestion("statdns.net.", dns.TypeNAPTR)
ret, err := dns.Exchange(m, "8.8.8.8:53")
if t, ok := ret.Answer[0].(*dns.NAPTR); ok {
// 使用 t.Order, t.Preference 等进行操作
}
在ret
中,你应该可以通过Answer
成员访问到[]RR
类型的数据。我假设你可以像上面的代码一样进行访问。
NAPTR类型中定义了可用的成员。
请注意:我暂时离开了我的工作站,无法尝试这段代码...
英文:
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...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论