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条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP