github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/dns/udp_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 TestUDP(t *testing.T) {
    14  	subnet, _ := netip.ParsePrefix("223.5.5.0/24")
    15  	s5Dialer := socks5.Dial("127.0.0.1", "1080", "", "")
    16  	configMap := map[string]Config{
    17  		"cloudflare": {
    18  			Type:   dns.Type_udp,
    19  			Host:   "one.one.one.one",
    20  			Subnet: subnet,
    21  			Dialer: s5Dialer,
    22  		},
    23  		"google": {
    24  			Type:   dns.Type_udp,
    25  			Host:   "8.8.8.8",
    26  			Subnet: subnet,
    27  			Dialer: s5Dialer,
    28  		},
    29  		"114": {
    30  			Type:   dns.Type_udp,
    31  			Host:   "114.114.114.114",
    32  			Subnet: subnet,
    33  		},
    34  		"nextdns": {
    35  			Type:   dns.Type_udp,
    36  			Host:   "45.90.28.30",
    37  			Subnet: subnet,
    38  			Dialer: s5Dialer,
    39  		},
    40  	}
    41  
    42  	dns, err := New(configMap["google"])
    43  	assert.NoError(t, err)
    44  
    45  	t.Log(dns.LookupIP(context.TODO(), "www.baidu.com"))
    46  	t.Log(dns.LookupIP(context.TODO(), "www.google.com"))
    47  	t.Log(dns.LookupIP(context.TODO(), "www.twitter.com"))
    48  	t.Log(dns.LookupIP(context.TODO(), "i2.hdslb.com"))
    49  }