SpoofDPI/doh/dns.go
2022-03-11 13:23:15 +09:00

42 lines
571 B
Go

package doh
import (
"errors"
"sync"
"github.com/babolivier/go-doh-client"
)
var resolver *doh.Resolver
var once sync.Once
func Init(dns string) {
getInstance().Host = dns
}
func Lookup(domain string) (string, error) {
a, _, err := resolver.LookupA(domain)
if err != nil {
return "", err
}
if len(a) < 1 {
return "", errors.New(" couldn't resolve the domain")
}
ip := a[0].IP4
return ip, nil
}
func getInstance() *doh.Resolver {
once.Do(func() {
resolver = &doh.Resolver{
Host: "",
Class: doh.IN,
}
})
return resolver
}