39 lines
616 B
Go
39 lines
616 B
Go
package dns
|
|
|
|
import (
|
|
"net"
|
|
"sort"
|
|
)
|
|
|
|
type Domain struct {
|
|
Name string
|
|
NS []string
|
|
}
|
|
|
|
func CheckDomain(domain string) Domain {
|
|
nameservers, err := net.LookupNS(domain)
|
|
|
|
if len(nameservers) > 0 && err == nil {
|
|
return Domain{
|
|
Name: domain,
|
|
NS: nsToArray(nameservers),
|
|
}
|
|
}
|
|
return Domain{
|
|
Name: domain,
|
|
NS: []string{},
|
|
}
|
|
}
|
|
|
|
func nsToArray(nameservers []*net.NS) []string {
|
|
var nsArray []string
|
|
for _, nameserver := range nameservers {
|
|
nsArray = append(nsArray, nameserver.Host)
|
|
}
|
|
|
|
sort.SliceStable(nsArray, func(i, j int) bool {
|
|
return nsArray[i] < nsArray[j]
|
|
})
|
|
|
|
return nsArray
|
|
}
|