Ejemplo n.º 1
0
// Use golang.org/x/net/proxy package to make a socks5 client.
// For more information, see DefaultTransport in net.http package.
func Socks5Client(conf ProxyConfig) (client *http.Client, err error) {

	var proxyAuth *proxy.Auth
	if conf.Username != "" {
		proxyAuth = new(proxy.Auth)
		proxyAuth.User = conf.Username
		proxyAuth.Password = conf.Password
	}

	dialer, err := proxy.SOCKS5(
		"tcp",
		conf.Addr,
		proxyAuth,
		&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		})
	if err != nil {
		return
	}

	var transport http.RoundTripper = &http.Transport{
		Proxy:               nil,
		Dial:                dialer.Dial,
		TLSHandshakeTimeout: 10 * time.Second,
	}

	client = &http.Client{Transport: transport}
	return
}
Ejemplo n.º 2
0
func socks5UnixProxy(u *url.URL, d proxy.Dialer) (proxy.Dialer, error) {
	var auth *proxy.Auth
	if u.User != nil {
		auth = &proxy.Auth{
			User: u.User.Username(),
		}

		if p, ok := u.User.Password(); ok {
			auth.Password = p
		}
	}

	return proxy.SOCKS5("unix", u.Path, auth, d)
}
Ejemplo n.º 3
0
Archivo: xmpp.go Proyecto: 0x27/coyim
func init() {
	proxy.RegisterDialerType("socks5+unix", func(u *url.URL, d proxy.Dialer) (proxy.Dialer, error) {
		var auth *proxy.Auth
		if u.User != nil {
			auth = &proxy.Auth{
				User: u.User.Username(),
			}

			if p, ok := u.User.Password(); ok {
				auth.Password = p
			}
		}

		return proxy.SOCKS5("unix", u.Path, auth, d)
	})
}