Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lixiangzhong/dnsutil
dns dig for golang
https://github.com/lixiangzhong/dnsutil
dig dns dns-dig go golang golang-library golang-package
Last synced: 21 days ago
JSON representation
dns dig for golang
- Host: GitHub
- URL: https://github.com/lixiangzhong/dnsutil
- Owner: lixiangzhong
- License: apache-2.0
- Created: 2016-05-11T01:23:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-28T01:33:24.000Z (10 months ago)
- Last Synced: 2024-11-17T12:50:13.710Z (25 days ago)
- Topics: dig, dns, dns-dig, go, golang, golang-library, golang-package
- Language: Go
- Homepage:
- Size: 1.14 MB
- Stars: 96
- Watchers: 6
- Forks: 40
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-hacking-lists - lixiangzhong/dnsutil - dns dig for golang (Go)
README
[![Go Report Card](https://goreportcard.com/badge/github.com/lixiangzhong/dnsutil)](https://goreportcard.com/report/lixiangzhong/dnsutil)
[![](https://godoc.org/github.com/lixiangzhong/dnsutil?status.svg)](https://godoc.org/github.com/lixiangzhong/dnsutil)# dnsutil
#### Golang DNS dig功能库```sh
go get github.com/lixiangzhong/dnsutil
``````go
//Normalpackage main
import (
"fmt"
"github.com/lixiangzhong/dnsutil"
)func main() {
var dig dnsutil.Dig
dig.SetDNS("8.8.8.8") //or ns.xxx.com
a, err := dig.A("google.com") // dig google.com @8.8.8.8
fmt.Println(a, err)
}
``````go
//msgpackage main
import (
"fmt"
"github.com/lixiangzhong/dnsutil"
"github.com/miekg/dns"
)func main() {
var dig dnsutil.Dig
dig.SetDNS("1.1.1.1")
msg, err := dig.GetMsg(dns.TypeA, "google.com")
if err != nil {
fmt.Println(err)
return
}
// fmt.Println(msg)
// or
fmt.Println(msg.Question) //question section
fmt.Println(msg.Answer) //answer section.
fmt.Println(msg.Ns) //authority section.
fmt.Println(msg.Extra) //additional section.
}```
```go
//EDNS0ClientSubnetpackage main
import (
"fmt"
"github.com/lixiangzhong/dnsutil"
)func main() {
var dig dnsutil.Dig
dig.SetDNS("8.8.8.8") //or ns.xxx.com
dig.SetEDNS0ClientSubnet("123.123.123.123") //support edns0clientsubnet
a, err := dig.A("google.com") // dig google.com @8.8.8.8 +client=123.123.123.123
fmt.Println(a, err)
}
``````go
//Retrypackage main
import (
"fmt"
"github.com/lixiangzhong/dnsutil"
)func main() {
var dig dnsutil.Dig
dig.Retry=3 //retry when write or read message return error . defualt 1
dig.SetDNS("8.8.8.8") //or ns.xxx.com
a, err := dig.A("google.com") // dig google.com @8.8.8.8
fmt.Println(a, err)
}
``````go
//dig +tracepackage main
import (
"fmt"
"github.com/lixiangzhong/dnsutil"
)func main() {
domain := "google.com"
var dig dnsutil.Dig
rsps, err := dig.Trace(domain) //dig +trace google.com
if err != nil {
fmt.Println(err)
return
}
for _, rsp := range rsps {
if rsp.Msg.Authoritative {
for _, answer := range rsp.Msg.Answer {
fmt.Println(answer)
}
}
for _, ns := range rsp.Msg.Ns {
fmt.Println(ns)
}
fmt.Println("\tReceived from", rsp.Server, rsp.ServerIP)
}
}
``````go
//检查是否被污染package main
import (
"fmt"
"github.com/lixiangzhong/dnsutil"
)func main() {
polluted, err := dnsutil.IsPolluted("facebook.com")
if err != nil {
fmt.Println(err)
return
}
if polluted {
fmt.Println("被污染,你懂的")
} else {
fmt.Println("正常")
}
}
``````go
//SetBackupDNS
//同时向设置的2个DNS发起请求,返回最快响应的那个结果
//Initiate requests to two DNS settings at the same time, returning the fastest response result
package mainimport (
"fmt"
"github.com/lixiangzhong/dnsutil"
)func main() {
var dig dnsutil.Dig
dig.SetDNS("1.1.1.1")
dig.SetBackupDNS("8.8.8.8")
a, err := dig.A("google.com")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(a)
}```