mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 22:36:53 +00:00
add dns module
This commit is contained in:
parent
a619dc2ad1
commit
7f68c38c7b
36
dns/dns.go
Normal file
36
dns/dns.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package dns
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/babolivier/go-doh-client"
|
||||||
|
)
|
||||||
|
|
||||||
|
var resolver *doh.Resolver
|
||||||
|
var once sync.Once
|
||||||
|
|
||||||
|
func Init(dns string) {
|
||||||
|
getInstance().Host = dns
|
||||||
|
}
|
||||||
|
|
||||||
|
func LookupOverHttps(domain string) (string, error) {
|
||||||
|
a, _, err := resolver.LookupA(domain)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
ip := a[0].IP4
|
||||||
|
|
||||||
|
return ip, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getInstance() *doh.Resolver {
|
||||||
|
once.Do(func() {
|
||||||
|
resolver = &doh.Resolver{
|
||||||
|
Host: "",
|
||||||
|
Class: doh.IN,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return resolver
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user