mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2024-12-22 14:26:31 +00:00
move doh.go into proxy module
This commit is contained in:
parent
cd3e46355b
commit
1a55f159d1
14
proxy/doh.go
Normal file
14
proxy/doh.go
Normal 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
|
||||||
|
}
|
@ -6,14 +6,14 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/babolivier/go-doh-client"
|
||||||
"github.com/pterm/pterm"
|
"github.com/pterm/pterm"
|
||||||
"github.com/xvzc/SpoofDPI/packet"
|
"github.com/xvzc/SpoofDPI/packet"
|
||||||
"github.com/xvzc/SpoofDPI/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Proxy struct {
|
type Proxy struct {
|
||||||
Port string
|
Port string
|
||||||
DNS string
|
DNS doh.Resolver
|
||||||
OS string
|
OS string
|
||||||
Debug bool
|
Debug bool
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ type Proxy struct {
|
|||||||
func New(port string, dns string, os string, debug bool) *Proxy {
|
func New(port string, dns string, os string, debug bool) *Proxy {
|
||||||
return &Proxy{
|
return &Proxy{
|
||||||
Port: port,
|
Port: port,
|
||||||
DNS: dns,
|
DNS: doh.Resolver{Host: dns, Class: doh.IN},
|
||||||
OS: os,
|
OS: os,
|
||||||
Debug: debug,
|
Debug: debug,
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ func (p *Proxy) PrintWelcome() {
|
|||||||
|
|
||||||
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
|
pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
|
||||||
{Level: 0, Text: "PORT : " + p.Port},
|
{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)},
|
{Level: 0, Text: "DEBUG : " + fmt.Sprint(p.Debug)},
|
||||||
}).Render()
|
}).Render()
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func (p *Proxy) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dns lookup over https
|
// Dns lookup over https
|
||||||
ip, err := util.DnsLookupOverHttps(p.DNS, r.Domain)
|
ip, err := p.DnsLookupOverHttps(r.Domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error looking up dns: "+r.Domain, err)
|
log.Println("Error looking up dns: "+r.Domain, err)
|
||||||
return
|
return
|
||||||
|
22
util/doh.go
22
util/doh.go
@ -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
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user