github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/proxy/socks5/client_test.go (about) 1 package socks5 2 3 import ( 4 "context" 5 "net" 6 "testing" 7 "time" 8 9 "github.com/Asutorufa/yuhaiin/pkg/net/nat" 10 "github.com/Asutorufa/yuhaiin/pkg/net/netapi" 11 "github.com/Asutorufa/yuhaiin/pkg/protos/statistic" 12 "github.com/Asutorufa/yuhaiin/pkg/utils/assert" 13 ) 14 15 func TestUDP(t *testing.T) { 16 p := Dial("127.0.0.1", "1080", "", "") 17 18 packet, err := p.PacketConn(context.TODO(), netapi.ParseAddressPort(statistic.Type_udp, "0.0.0.0", netapi.EmptyPort)) 19 assert.NoError(t, err) 20 defer packet.Close() 21 22 req := []byte{46, 230, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 7, 98, 114, 111, 119, 115, 101, 114, 4, 112, 105, 112, 101, 4, 97, 114, 105, 97, 9, 109, 105, 99, 114, 111, 115, 111, 102, 116, 3, 99, 111, 109, 0, 0, 1, 0, 1, 0, 0, 41, 16, 0, 0, 0, 0, 0, 0, 12, 0, 8, 0, 8, 0, 1, 22, 0, 223, 5, 4, 0} 23 24 _, err = packet.WriteTo(req, &net.UDPAddr{IP: net.ParseIP("1.1.1.1"), Port: 53}) 25 assert.NoError(t, err) 26 27 _, err = packet.WriteTo(req, &net.UDPAddr{IP: net.ParseIP("8.8.8.8"), Port: 53}) 28 assert.NoError(t, err) 29 30 buf := make([]byte, nat.MaxSegmentSize) 31 32 for { 33 _ = packet.SetReadDeadline(time.Now().Add(time.Second * 5)) 34 35 n, src, err := packet.ReadFrom(buf) 36 assert.NoError(t, err) 37 38 t.Log("read from", src, "data:", n) 39 } 40 }