From 4d184f7f8671ad6e868afcccd245596df33b8623 Mon Sep 17 00:00:00 2001 From: jerry901 Date: Sun, 8 May 2022 22:21:49 +0900 Subject: [PATCH] add raw ip support --- doh/dns.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doh/dns.go b/doh/dns.go index 77b2c08..c3527ff 100644 --- a/doh/dns.go +++ b/doh/dns.go @@ -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