discordBots/cmd/domaincheckbot/dns/domain.go
2023-03-10 00:26:08 +01:00

35 lines
657 B
Go

package dns
import (
"grow.rievo.dev/discordBots/cmd/domaincheckbot/repository"
"net"
"sort"
)
func CheckDomain(domain string) repository.Domain {
nameservers, err := net.LookupNS(domain)
if len(nameservers) > 0 && err == nil {
return repository.Domain{
Name: domain,
NS: nsToArray(nameservers),
}
}
return repository.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
}