Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a go socks5 client

Tags:

go

socks

So I'm looking at the net/proxy docs and there is no examples at all of how to use any of its methods. I'm looking into using socks5. This is the how the function looks:

func SOCKS5(network, addr string, auth *Auth, forward Dialer) (Dialer, error)

Now everything kinda makes sense except I'm confused about forward which is a type Dialer and the function itself returns a Dialer. Everything else makes sense network, add, auth just forward is throwing me off. How would I set my client up to use the socks5 Dialer?

like image 745
Rodrigo Avatar asked Nov 07 '15 17:11

Rodrigo


People also ask

Are SOCKS5 free?

SOCKS5 proxy is a popular solution for hiding your location on the internet and unblocking geo-restricted content. SOCKS 5 proxy from VPN Unlimited is totally free and easily the best among its counterparts!

How do I setup a SOCKS5 proxy on Windows 10?

To configure a SOCKS Proxy Server on Windows 10, go to: Settings > Network & Internet > Proxy. Or you can also go through: Control Panel > Network and Internet > Internet Options > Connections “tab” > LAN Settings > Proxy server.


2 Answers

So I was able to find the answer to my question anyone interested how to set up a socks5 client in go here it is:

dialSocksProxy, err := proxy.SOCKS5("tcp", "proxy_ip", nil, proxy.Direct)
if err != nil {
    fmt.Println("Error connecting to proxy:", err)
}
tr := &http.Transport{Dial: dialSocksProxy.Dial}

// Create client
myClient := &http.Client{
    Transport: tr,
}
like image 55
Rodrigo Avatar answered Sep 28 '22 04:09

Rodrigo


Recent versions of Go also have SOCKS5 proxy support via the HTTP_PROXY environment variable. You would write your http.Client code as usual, then just set the environment variable at runtime, for example:

HTTP_PROXY="socks5://127.0.0.1:1080/" ./myGoHttpClient
like image 20
likebike Avatar answered Sep 28 '22 06:09

likebike