godns/utils/utils.go

26 lines
417 B
Go
Raw Permalink Normal View History

2020-01-25 17:43:02 +00:00
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
}