0

I'm trying to dial using credentials and maintain a connection with a socks5 proxy server in Go.

This works nicely if I have IP authorisation set up with the proxy provider, however there is no way pass any auth credentials using net.Dial function in Go:

package main

import (
    "io"
    "net"
)

func main() {

    dst, err := net.Dial("tcp", "11.22.33.44:1111")
    if err != nil {
        panic("Dial Error:" + err.Error())
    }

    dst.Close()
}

Go has a useful proxy library and allows authenticated forward requests via proxy using this:

package main

import (
    "io"
    "net"
)

func main() {

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

    proxyconn, _ := proxy.SOCKS5("tcp", "11.11.11.11:1111", proxyAuth, nil) //returns a Dialer with proxy that can be invoked to connect to another address

    dst := proxyconn.Dial("tcp", "22.33.44.55:6666") //connects to an address via proxy

    dst.Close()
}

However it returns a Dialer that then asks to connect a target/ultimate address through this authenticated proxy rather the proxy server itself:

My objective here is to return a net.conn connection with a credentials-authenticated proxy server - something like this:

package main

import (
    "io"
    "net"
)

func main() {

    //net.Dial does not have a way to pass Auth creds
    dst := net.Dial("tcp", "22.33.44.55:6666", proxyAuth)

    dst.Close()
}
2
  • Why do you want a connection to the proxy? Commented Nov 30, 2021 at 10:34
  • Building a native Go proxy Squid-like app. The server side would listen in on localhost and reroute the requests made by the client through an authenticated proxy. Works fine if I have IP authorisation set up with proxy provider as per the first example. Commented Nov 30, 2021 at 11:28

1 Answer 1

0

The net.Dial() method doesn't concerned with proxy authentication. However, If you want proxy authentication you can set it in header of the request before the call. Please refer this link

dst := net.Dial("tcp", "22.33.44.55:6666")
Sign up to request clarification or add additional context in comments.

1 Comment

This seems to be applicable for HTTP forwarding only rather than SOCK5. It's a neat workaround but doesn't not entirely fit my needs unfortunately.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.