doulun1666 2019-03-06 19:20
浏览 282
已采纳

提取特定域的所有TXT记录

I want to extract the TXT Records of a particular domain in Go. I looked at a bunch of blogs and tried the following code:

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
", txt)
        }

}

When I execute this program, I get the following output.

docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e
facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95
globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8=
v=spf1 include:_spf.google.com ~all

This is working according to my requirement as I follow https://www.kitterman.com/spf/validate.html to validate if I am getting the correct output.

Now, whenever I change my Input Domain to geckoboard.com (say), I get the following error:

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

I get the fact that this is a Timeout Exception. However, when I run the same query on https://www.kitterman.com/spf/validate.html, I get the expected result within a fraction of seconds.

Is there any better way for extracting TXT Records other than using net.LookupTXT("google.com")? If not, can someone suggest me a good retry mechanism for the same code with a higher timeout value?

Update 1: Tried the answer provided by @Florian Weimer but still getting a timeout.

$ 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

Update 2: As suggested by @ThunderCat, I set the timeout to a much higher value. I added options timeout:30 in resolver.conf . Both queries, the dig and my program run for a period over 30 seconds before getting a timeout.

  • 写回答

2条回答 默认 最新

  • duandai7601 2019-03-08 07:03
    关注

    Thanks, @Florian Weimer for your help. I have got this working with a small extension your dig command.

    $ 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"
    

    My Golang code for the same is:

    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)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?