mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-03 04:50:11 +00:00
feat: ipv6 joins the ride.
This commit is contained in:
parent
a86b7b3d07
commit
714daeab99
15
dns/dns.go
15
dns/dns.go
@ -90,10 +90,17 @@ func dohLookup(domain string) (string, error) {
|
||||
|
||||
dnsUpstream := util.GetConfig().DnsAddr
|
||||
client := GetDoHClient(*dnsUpstream)
|
||||
resp, err := client.Resolve(domain, dns.TypeA)
|
||||
if err != nil {
|
||||
return "", errors.New("couldn not resolve the domain(doh)")
|
||||
// try up to 3 times
|
||||
for i := 0; i < 3; i++ {
|
||||
resp, err := client.Resolve(domain, []uint16{dns.TypeA, dns.TypeAAAA})
|
||||
if err == nil {
|
||||
if len(resp) == 0 { // yes this happens
|
||||
return "", errors.New("no record found(doh)")
|
||||
}
|
||||
|
||||
return resp[0], nil
|
||||
}
|
||||
}
|
||||
|
||||
return resp[0], nil
|
||||
return "", errors.New("could not resolve the domain(doh)")
|
||||
}
|
||||
|
35
dns/doh.go
35
dns/doh.go
@ -88,20 +88,31 @@ func (d *DoHClient) doGetRequest(msg *dns.Msg) (*dns.Msg, error) {
|
||||
return ret_msg, nil
|
||||
}
|
||||
|
||||
func (d *DoHClient) Resolve(domain string, dnsType uint16) ([]string, error) {
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dnsType)
|
||||
|
||||
resp, err := d.doGetRequest(msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (d *DoHClient) Resolve(domain string, dnsTypes []uint16) ([]string, error) {
|
||||
var ret []string
|
||||
for _, ans := range resp.Answer {
|
||||
if a, ok := ans.(*dns.A); ok {
|
||||
ret = append(ret, a.A.String())
|
||||
|
||||
for _, dnsType := range dnsTypes {
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(dns.Fqdn(domain), dnsType)
|
||||
|
||||
resp, err := d.doGetRequest(msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.Rcode != dns.RcodeSuccess {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, answer := range resp.Answer {
|
||||
if t, ok := answer.(*dns.A); ok {
|
||||
ret = append(ret, t.A.String())
|
||||
}
|
||||
if t, ok := answer.(*dns.AAAA); ok {
|
||||
ret = append(ret, t.AAAA.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user