github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/net/proxy/socks5.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package proxy 6 7 import ( 8 "context" 9 "net" 10 11 "golang.org/x/net/internal/socks" 12 ) 13 14 // SOCKS5 returns a Dialer that makes SOCKSv5 connections to the given 15 // address with an optional username and password. 16 // See RFC 1928 and RFC 1929. 17 func SOCKS5(network, address string, auth *Auth, forward Dialer) (Dialer, error) { 18 d := socks.NewDialer(network, address) 19 if forward != nil { 20 d.ProxyDial = func(_ context.Context, network string, address string) (net.Conn, error) { 21 return forward.Dial(network, address) 22 } 23 } 24 if auth != nil { 25 up := socks.UsernamePassword{ 26 Username: auth.User, 27 Password: auth.Password, 28 } 29 d.AuthMethods = []socks.AuthMethod{ 30 socks.AuthMethodNotRequired, 31 socks.AuthMethodUsernamePassword, 32 } 33 d.Authenticate = up.Authenticate 34 } 35 return d, nil 36 }