douliang2935 2018-04-17 03:26
浏览 125

在golang中询问LookupTXT函数

How do I change the IP address of the DNS server?

In situation, I set Google DNS server in Windows Network Settins.

And I use LookupTXT function in Golang for getting DNS txt request. But LookupTXT parameter is just the query string.

Any help or pointers would be highly appreciated. Thanks!

  • 写回答

1条回答 默认 最新

  • duanjinchen5296 2018-04-17 03:48
    关注

    This is not straigtforward to do using golang at this point. You can however use a third party DNS package that allows configuring the resolver. First install the package:

    go get github.com/bogdanovich/dns_resolver
    

    Here is an example using it and the google resolvers 8.8.8.8 and 8.8.4.4:

    package main
    
    import (
        "log"
        "github.com/bogdanovich/dns_resolver"
    )
    
    func main() {
        resolver := dns_resolver.New([]string{"8.8.8.8", "8.8.4.4"})
    
        // In case of i/o timeout
        resolver.RetryTimes = 5
    
        ip, err := resolver.LookupHost("google.com")
        if err != nil {
            log.Fatal(err.Error())
        }
        log.Println(ip)
        // Output [216.58.192.46]
    }
    

    Source

    There is an open issue in golang here, so hopefully it becomes easier to do it with the builtin net package: https://github.com/golang/go/issues/12503. It could just be a documentation problem, as it is possible now, I just can't find an example.

    EDIT: actually that package only supports lookupHost: https://github.com/bogdanovich/dns_resolver/blob/master/dns_resolver.go#L51-L79

    So a PR would be required to add a TXT resolver.

    2nd Edit: I made a PR with txt lookup here. That project hasn't been touched in years though so it may never get accepted.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)