如何在Go中查找NAPTR记录?

huangapple go评论150阅读模式
英文:

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...

huangapple
  • 本文由 发表于 2013年12月23日 00:32:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/20731536.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定