-
Notifications
You must be signed in to change notification settings - Fork 75
/
example_test.go
97 lines (88 loc) · 1.7 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package socks
import (
"net"
"net/http"
"net/http/httputil"
)
func ExampleSocks5Client() {
user := ""
password := ""
client, err := NewSocks5Client("tcp", "127.0.0.1:1080", user, password, Direct)
if err != nil {
return
}
conn, err := client.Dial("tcp", "www.google.com:80")
if err != nil {
return
}
httpClient := httputil.NewClientConn(conn, nil)
defer httpClient.Close()
request, err := http.NewRequest("GET", "/", nil)
if err != nil {
return
}
resp, err := httpClient.Do(request)
if err != nil {
return
}
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
return
}
println(string(dump))
return
}
func ExampleSocks5Server() {
listener, err := net.Listen("tcp", ":1080")
if err != nil {
return
}
defer listener.Close()
if server, err := NewSocks5Server(Direct); err == nil {
server.Serve(listener)
}
}
func ExampleSocks4Client() {
user := ""
client, err := NewSocks4Client("tcp", "127.0.0.1:1080", user, Direct)
if err != nil {
return
}
addrs, err := net.LookupHost("www.google.com")
if err != nil {
return
}
if len(addrs) == 0 {
return
}
conn, err := client.Dial("tcp", addrs[0]+":80")
if err != nil {
return
}
httpClient := httputil.NewClientConn(conn, nil)
defer httpClient.Close()
request, err := http.NewRequest("GET", "/", nil)
if err != nil {
return
}
resp, err := httpClient.Do(request)
if err != nil {
return
}
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
return
}
println(string(dump))
return
}
func ExampleSocks4Server() {
listener, err := net.Listen("tcp", ":1080")
if err != nil {
return
}
defer listener.Close()
if server, err := NewSocks4Server(Direct); err == nil {
server.Serve(listener)
}
}