Go 提取特定域的所有TXT记录

Go 提取特定域的所有TXT记录,go,dns,spf,domain-record,Go,Dns,Spf,Domain Record,我想在Go中提取特定域的TXT记录。我查看了一堆博客,并尝试了以下代码: package main import ( "fmt" "net" ) func main() { txts, err := net.LookupTXT("google.com") if err != nil { panic(err) } if len(txts) == 0 {

我想在Go中提取特定域的TXT记录。我查看了一堆博客,并尝试了以下代码:

package main

import (
        "fmt"
        "net"
)

func main() {
        txts, err := net.LookupTXT("google.com")
        if err != nil {
                panic(err)
        }
        if len(txts) == 0 {
                fmt.Printf("no record")
        }
        for _, txt := range txts {
                fmt.Printf("%s\n", txt)
        }

}
当我执行这个程序时,我得到以下输出

docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e
facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95
globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=
v=spf1 include:_spf.google.com ~all
这是根据我的要求,因为我遵循验证我是否得到正确的输出

现在,每当我将输入域更改为geckoboard.com(比如),我都会得到以下错误:

panic: lookup geckoboard.com on 127.0.0.53:53: read udp 127.0.0.1:38440->127.0.0.53:53: i/o timeout   
goroutine 1 [running]: 
main.main()     
          /home/maruthi/emailheader.go:11
+0x190 exit status 2
我知道这是一个超时异常。然而,当我在上运行相同的查询时,我在几秒钟内得到了预期的结果

除了使用
net.lookuptext(“google.com”)
,还有什么更好的方法提取TXT记录吗?如果没有,有人能给我建议一个好的重试机制,用于超时值较高的相同代码吗

更新1:尝试了@Florian Weimer提供的答案,但仍然超时

$ dig +ignore +bufsize=512 geckoboard.com txt
; <<>> DiG 9.11.3-1ubuntu1.5-Ubuntu <<>> +ignore +bufsize=512 geckoboard.com txt
;; global options: +cmd
;; connection timed out; no servers could be reached
$dig+ignore+bufsize=512 geckoboard.com txt
;  DiG 9.11.3-1ubuntu1.5-Ubuntu+ignore+bufsize=512 geckoboard.com txt
;; 全局选项:+cmd
;; 连接超时;无法访问任何服务器

更新2:根据@ThunderCat的建议,我将超时设置为更高的值。我在resolver.conf中添加了
选项超时:30
。这两个查询、
dig
和我的程序在超时之前都会运行30秒以上。

递归解析器可能配置错误或刚刚损坏。它可能无法正确处理EDN,或者根本无法处理TCP查询。(一些客户端虚拟化解决方案具有内置DNS转发器,这些转发器存在这些问题。)

$ dig +ignore +bufsize=512 geckoboard.com txt
; <<>> DiG 9.11.3-1ubuntu1.5-Ubuntu <<>> +ignore +bufsize=512 geckoboard.com txt
;; global options: +cmd
;; connection timed out; no servers could be reached
需要TCP的原因是响应大小大于512字节:

$dig+ignore+bufsize=512 geckoboard.com txt
;  DiG 9.10.3-P4-Debian+ignore+bufsize=512 geckoboard.com txt
;; 全局选项:+cmd
;; 得到答案:

;; ->>头谢谢@Florian Weimer对你的帮助。我使用了一个小扩展名
dig
命令来实现这一点

$ dig @8.8.8.8 +ignore +short +bufsize=1024 geckoboard.com txt
"MS=ms20890953"
"facebook-domain-verification=uh1r0ebrc3sig0h2za0djoj4mhkn3g"
"google-site-verification=I6OUOqinHxPNuD8YBb3-c8GQA7YkbeHdx0xwUeeGLqI"
"google-site-verification=PWaSMmjvCe_daQC2-b7cZ9UW4rFt6Y8ZWQ7YoRbhMDw"
"google-site-verification=lSxvRgW-oP91yihSZ1kNv57EfgT97tmErxAjv5HFi2Q"
"spf2.0/pra include:spf.recurly.com ~all"
"status-page-domain-verification=8963fbq9nrjx"
"v=spf1 include:_spf.google.com include:sendgrid.net include:spf.recurly.com include:mail.zendesk.com include:servers.mcsv.net ~all"
我的Golang代码为:

package main

import (
    "fmt"
    "os/exec"
)

func main() {
    out, err := exec.Command("bash", "-c", "dig @8.8.8.8 +ignore +short +bufsize=1024 geckoboard.com txt").Output()
    s := string(out[:])

    if err != nil {
        fmt.Println("Unexpected Error Occured ", err)
    }
    fmt.Printf(s)
}

标题谈到寻找一种获取TXT记录的“有效”方法,但正文似乎与操作的效率没有任何关系-你能澄清一下吗?@Adrian谢谢,因为我在许多输入情况下都有一个超时,我想知道在没有这些超时异常的情况下实现输出的最佳方法。对不起,我已经修改了问题标题,在resolv.conf@ThunderCat中设置了更长的超时时间。我已经更新了我的问题,请看一下