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

     1  package dns
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"io"
     7  	"net"
     8  	"net/http"
     9  	"testing"
    10  
    11  	"github.com/Asutorufa/yuhaiin/pkg/net/netapi"
    12  	"github.com/Asutorufa/yuhaiin/pkg/net/proxy/socks5"
    13  )
    14  
    15  func TestDNSJson(t *testing.T) {
    16  	dialContext := func(ctx context.Context, network, addr string) (net.Conn, error) {
    17  		ad, err := netapi.ParseAddress(netapi.PaseNetwork(network), addr)
    18  		if err != nil {
    19  			return nil, fmt.Errorf("parse address failed: %w", err)
    20  		}
    21  		return socks5.Dial("127.0.0.1", "1080", "", "").Conn(ctx, ad)
    22  	}
    23  	t.Log(DOHJsonAPI("https://dns.rubyfish.cn/dns-query", "dict.hjenglish.com", dialContext))
    24  	t.Log(DOHJsonAPI("https://dns.rubyfish.cn/dns-query", "i0.hdslb.com", nil))
    25  	t.Log(DOHJsonAPI("https://dns.rubyfish.cn/dns-query", "cm.bilibili.com", nil))
    26  	t.Log(DOHJsonAPI("https://dns.google/resolve", "dict.hjenglish.com", dialContext))
    27  	t.Log(DOHJsonAPI("https://dns.google/resolve", "i0.hdslb.com", dialContext))
    28  }
    29  
    30  func TestC(t *testing.T) {
    31  	req, _ := http.NewRequest("GET", "https://cloudflare-dns.com/dns-query"+"?dns="+"q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB", nil)
    32  	req.Header.Set("accept", "application/dns-message")
    33  	//res, err := http.Get("https://cloudflare-dns.com/dns-query"+"?dns="+base64.URLEncoding.EncodeToString([]byte("cm.bilibili.com")))
    34  	client := &http.Client{}
    35  	res, err := client.Do(req)
    36  	if err != nil {
    37  		t.Log(err)
    38  	}
    39  	body, err := io.ReadAll(res.Body)
    40  	if err != nil {
    41  		t.Log("Read error", err)
    42  	}
    43  	t.Log(string(body))
    44  }