SOCKS5 proxy support

This commit is contained in:
Paul Kilar
2017-10-10 15:04:15 +01:00
parent c85cf0483a
commit d9b404fa00
3 changed files with 46 additions and 0 deletions
+20
View File
@@ -6,6 +6,7 @@ import (
"time"
"golang.org/x/crypto/ssh"
"golang.org/x/net/proxy"
)
// ConnectFunc is a convenience method for returning a function
@@ -27,6 +28,25 @@ func ConnectFunc(network, addr string) func() (net.Conn, error) {
}
}
// ConnectFunc is a convenience method for returning a function
// that connects to a host using SOCKS5 proxy
func ProxyConnectFunc(socksProxy string, socksAuth *proxy.Auth, network, addr string) func() (net.Conn, error) {
return func() (net.Conn, error) {
// create a socks5 dialer
dialer, err := proxy.SOCKS5("tcp", socksProxy, socksAuth, proxy.Direct)
if err != nil {
return nil, fmt.Errorf("Can't connect to the proxy: %s", err)
}
c, err := dialer.Dial(network, addr)
if err != nil {
return nil, err
}
return c, nil
}
}
// BastionConnectFunc is a convenience method for returning a function
// that connects to a host over a bastion connection.
func BastionConnectFunc(