github.com/zooyer/miskit@v1.0.71/dns/dns_test.go (about) 1 /** 2 * @Author: zzy 3 * @Email: zhangzhongyuan@didiglobal.com 4 * @Description: 5 * @File: dns_test.go 6 * @Package: dns 7 * @Version: 1.0.0 8 * @Date: 2022/9/28 16:37 9 */ 10 11 package dns 12 13 import ( 14 "net" 15 "testing" 16 17 "golang.org/x/net/dns/dnsmessage" 18 ) 19 20 func TestLookupIP(t *testing.T) { 21 addrs, err := net.LookupIP("vpn.zb.genkitol.com") 22 if err != nil { 23 t.Fatal(err) 24 } 25 26 for _, addr := range addrs { 27 t.Log(addr) 28 } 29 } 30 31 func TestHookHosts(t *testing.T) { 32 var hosts = map[string][]dnsmessage.Resource{ 33 "zzy": { 34 { 35 Header: dnsmessage.ResourceHeader{ 36 Name: dnsmessage.MustNewName("zzy"), 37 Type: dnsmessage.TypeA, 38 Class: dnsmessage.ClassINET, 39 TTL: 600, 40 Length: 0, 41 }, 42 Body: &dnsmessage.AResource{ 43 A: [4]byte{110, 110, 110, 110}, 44 }, 45 }, 46 { 47 Header: dnsmessage.ResourceHeader{ 48 Name: dnsmessage.MustNewName("zzy"), 49 Type: dnsmessage.TypeAAAA, 50 Class: dnsmessage.ClassINET, 51 TTL: 600, 52 Length: 0, 53 }, 54 Body: &dnsmessage.AAAAResource{ 55 AAAA: [16]byte{0x24, 0x08, 0x82, 0x1b, 0x71, 0x10, 0x19, 0x10, 0x2e, 0xb2, 0x1a, 0xff, 0xfe, 0xca, 0x21, 0x9d}, 56 }, 57 }, 58 }, 59 } 60 61 if err := HookHosts(hosts); err != nil { 62 t.Fatal(err) 63 } 64 } 65 66 func TestHookHostsByText(t *testing.T) { 67 var hosts = map[string][]string{ 68 "zzy": { 69 "110.110.110.110", 70 "2408:821b:7110:1910:2eb2:1aff:feca:219d", 71 }, 72 } 73 74 if err := HookHostsByText(hosts); err != nil { 75 t.Fatal(err) 76 } 77 } 78 79 func TestHookHostsByLocal(t *testing.T) { 80 if err := HookHostsByLocal("zzy", "ll"); err != nil { 81 t.Fatal(err) 82 } 83 }