add raw ip support

This commit is contained in:
jerry901 2022-05-08 22:21:49 +09:00
parent 20e2065109
commit 4d184f7f86

View File

@ -4,6 +4,7 @@ import (
"errors"
"sync"
"regexp"
"github.com/babolivier/go-doh-client"
)
@ -15,6 +16,13 @@ func Init(dns string) {
}
func Lookup(domain string) (string, error) {
ipRegex := "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
if r, _ := regexp.MatchString(ipRegex, domain); r {
return domain, nil
}
a, _, err := resolver.LookupA(domain)
if err != nil {
return "", err