github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/dns/dot_test.go (about)

     1  package dns
     2  
     3  import (
     4  	"context"
     5  	"net/netip"
     6  	"testing"
     7  
     8  	"github.com/Asutorufa/yuhaiin/pkg/net/proxy/socks5"
     9  	"github.com/Asutorufa/yuhaiin/pkg/protos/config/dns"
    10  	"github.com/Asutorufa/yuhaiin/pkg/utils/assert"
    11  )
    12  
    13  func TestDOT(t *testing.T) {
    14  	s, _ := netip.ParsePrefix("223.5.5.5/22")
    15  	configMap := map[string]Config{
    16  		"google": {
    17  			Type:   dns.Type_dot,
    18  			Host:   "8.8.8.8",
    19  			Subnet: s,
    20  			Dialer: socks5.Dial("127.0.0.1", "1080", "", ""),
    21  		},
    22  		"ali": {
    23  			Type:   dns.Type_dot,
    24  			Host:   "223.5.5.5",
    25  			Subnet: s,
    26  		},
    27  		"dnspub": {
    28  			Type:   dns.Type_dot,
    29  			Host:   "dot.pub:853",
    30  			Subnet: s,
    31  		},
    32  		"360": {
    33  			Type:   dns.Type_dot,
    34  			Host:   "dot.360.cn:853",
    35  			Subnet: s,
    36  		},
    37  	}
    38  
    39  	d, err := New(configMap["google"])
    40  	assert.NoError(t, err)
    41  
    42  	t.Log(d.LookupIP(context.TODO(), "i2.hdslb.com"))
    43  	t.Log(d.LookupIP(context.TODO(), "www.google.com"))
    44  	t.Log(d.LookupIP(context.TODO(), "www.baidu.com"))
    45  	t.Log(d.LookupIP(context.TODO(), "www.apple.com"))
    46  	t.Log(d.LookupIP(context.TODO(), "www.example.com"))
    47  }