move doh.go into proxy module

This commit is contained in:
xvzc 2022-01-09 01:02:30 +09:00
parent cd3e46355b
commit 1a55f159d1
3 changed files with 19 additions and 27 deletions

14
proxy/doh.go Normal file
View File

@ -0,0 +1,14 @@
package proxy
func (p *Proxy) DnsLookupOverHttps(domain string) (string, error) {
// Perform a A lookup on example.com
a, _, err := p.DNS.LookupA(domain)
if err != nil {
return "", err
}
ip := a[0].IP4
return ip, nil
}

View File

@ -6,14 +6,14 @@ import (
"net"
"os"
"github.com/babolivier/go-doh-client"
"github.com/pterm/pterm"
"github.com/xvzc/SpoofDPI/packet"
"github.com/xvzc/SpoofDPI/util"
)
type Proxy struct {
Port string
DNS string
DNS doh.Resolver
OS string
Debug bool
}
@ -21,7 +21,7 @@ type Proxy struct {
func New(port string, dns string, os string, debug bool) *Proxy {
return &Proxy{
Port: port,
DNS: dns,
DNS: doh.Resolver{Host: dns, Class: doh.IN},
OS: os,
Debug: debug,
}
@ -34,7 +34,7 @@ func (p *Proxy) PrintWelcome() {
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
{Level: 0, Text: "PORT : " + p.Port},
{Level: 0, Text: "DNS : " + p.DNS},
{Level: 0, Text: "DNS : " + p.DNS.Host},
{Level: 0, Text: "DEBUG : " + fmt.Sprint(p.Debug)},
}).Render()
}
@ -76,7 +76,7 @@ func (p *Proxy) Start() {
}
// Dns lookup over https
ip, err := util.DnsLookupOverHttps(p.DNS, r.Domain)
ip, err := p.DnsLookupOverHttps(r.Domain)
if err != nil {
log.Println("Error looking up dns: "+r.Domain, err)
return

View File

@ -1,22 +0,0 @@
package util
import (
"github.com/babolivier/go-doh-client"
)
func DnsLookupOverHttps(dns string, domain string) (string, error) {
// Perform a A lookup on example.com
resolver := doh.Resolver{
Host: dns, // Change this with your favourite DoH-compliant resolver.
Class: doh.IN,
}
a, _, err := resolver.LookupA(domain)
if err != nil {
return "", err
}
ip := a[0].IP4
return ip, nil
}