...
1
2
3
4
5 package proxy
6
7 import (
8 "context"
9 "net"
10
11 "golang.org/x/net/internal/socks"
12 )
13
14
15
16
17 func SOCKS5(network, address string, auth *Auth, forward Dialer) (Dialer, error) {
18 d := socks.NewDialer(network, address)
19 if forward != nil {
20 if f, ok := forward.(ContextDialer); ok {
21 d.ProxyDial = func(ctx context.Context, network string, address string) (net.Conn, error) {
22 return f.DialContext(ctx, network, address)
23 }
24 } else {
25 d.ProxyDial = func(ctx context.Context, network string, address string) (net.Conn, error) {
26 return dialContext(ctx, forward, network, address)
27 }
28 }
29 }
30 if auth != nil {
31 up := socks.UsernamePassword{
32 Username: auth.User,
33 Password: auth.Password,
34 }
35 d.AuthMethods = []socks.AuthMethod{
36 socks.AuthMethodNotRequired,
37 socks.AuthMethodUsernamePassword,
38 }
39 d.Authenticate = up.Authenticate
40 }
41 return d, nil
42 }
43
View as plain text