mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
enhance logging for dns
This commit is contained in:
parent
378b980301
commit
10a3860fad
12
dns/dns.go
12
dns/dns.go
@ -4,8 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/likexian/doh"
|
"github.com/likexian/doh"
|
||||||
dohDns "github.com/likexian/doh/dns"
|
dohDns "github.com/likexian/doh/dns"
|
||||||
@ -53,12 +53,12 @@ func (d *DnsResolver) Lookup(domain string) (string, error) {
|
|||||||
|
|
||||||
for _, answer := range response.Answer {
|
for _, answer := range response.Answer {
|
||||||
if record, ok := answer.(*dns.A); ok {
|
if record, ok := answer.(*dns.A); ok {
|
||||||
log.Debug("[DNS] resolved dns for "+domain+": ", record.A.String())
|
log.Debug("[DNS] resolved ", domain, ": ", record.A.String())
|
||||||
return record.A.String(), nil
|
return record.A.String(), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", errors.New("couldn not resolve the domain")
|
return "", errors.New("no record found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func dohLookup(domain string) (string, error) {
|
func dohLookup(domain string) (string, error) {
|
||||||
@ -68,7 +68,7 @@ func dohLookup(domain string) (string, error) {
|
|||||||
|
|
||||||
rsp, err := c.Query(ctx, dohDns.Domain(domain), dohDns.TypeA)
|
rsp, err := c.Query(ctx, dohDns.Domain(domain), dohDns.TypeA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.New("could not resolve the domain")
|
return "", errors.New("could not resolve the domain")
|
||||||
}
|
}
|
||||||
// doh dns answer
|
// doh dns answer
|
||||||
answer := rsp.Answer
|
answer := rsp.Answer
|
||||||
@ -79,12 +79,12 @@ func dohLookup(domain string) (string, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("[DOH] resolved dns for "+domain+": ", a.Data)
|
log.Debug("[DOH] resolved ", domain, ": ", a.Data)
|
||||||
return a.Data, nil
|
return a.Data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// close the client
|
// close the client
|
||||||
c.Close()
|
c.Close()
|
||||||
|
|
||||||
return "", errors.New("couldn not resolve the domain")
|
return "", errors.New("no record found")
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func (pxy *Proxy) Start() {
|
|||||||
|
|
||||||
ip, err := pxy.resolver.Lookup(pkt.Domain())
|
ip, err := pxy.resolver.Lookup(pkt.Domain())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[PROXY] Error looking up for domain with ", pkt.Domain(), " ", err)
|
log.Error("[PROXY] Error while dns lookup: ", pkt.Domain(), " ", err)
|
||||||
conn.Write([]byte(pkt.Version() + " 502 Bad Gateway\r\n\r\n"))
|
conn.Write([]byte(pkt.Version() + " 502 Bad Gateway\r\n\r\n"))
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user