godns/utils/utils.go
2020-01-25 12:43:02 -05:00

26 lines
417 B
Go

package utils
import (
"github.com/miekg/dns"
"net"
"regexp"
)
func IsDomain(domain string) bool {
if IsIP(domain) {
return false
}
match, _ := regexp.MatchString(`^([a-zA-Z0-9\*]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$`, domain)
return match
}
func IsIP(ip string) bool {
return net.ParseIP(ip) != nil
}
func UnFqdn(s string) string {
if dns.IsFqdn(s) {
return s[:len(s)-1]
}
return s
}