Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minimal SOCKS5 proxy server in Go
// For use in the tutorial at https://blog.simos.info/a-network-isolated-container-in-lxd/
// Source: https://github.com/armon/go-socks5
//
// To compile, run once: go get github.com/armon/go-socks5
// then run: go run simplesocks5proxyserver.go
//
package main
import (
"fmt"
"log"
"os"
"github.com/armon/go-socks5"
)
func main() {
// Create a SOCKS5 server
config := &socks5.Config{
Logger: log.New(os.Stdout, "SOCKS5Server", log.LstdFlags),
}
server, err := socks5.New(config)
if err != nil {
panic(err)
}
fmt.Print("Listening on 127.0.0.1:10080...\n");
fmt.Print("Press Ctrl+C to interrupt: ");
// Create SOCKS5 proxy on localhost port 1080
if err := server.ListenAndServe("tcp", "127.0.0.1:10080"); err != nil {
panic(err)
}
}
@derekmahar

This comment has been minimized.

Copy link

derekmahar commented May 16, 2020

@simos, what should I do to resolve this compilation error? The Go compiler apparently misinterprets the go-socks5 module import as a local import.

derek@derek-TB350-BTC:~/Projects/go/35c6aa259cab05fd56c19ad6b0cfdd0f$ go run simplesocks5proxyserver.go
simplesocks5proxyserver.go:11:5: cannot find package "github.com/armon/go-socks5" in any of:
        /snap/go/5759/src/github.com/armon/go-socks5 (from $GOROOT)
        /home/derek/go/src/github.com/armon/go-socks5 (from $GOPATH)
@simos

This comment has been minimized.

Copy link
Owner Author

simos commented May 16, 2020

@derekmahar, indeed, you get this error when you build this Go code.

Run first,

go get github.com/armon/go-socks5

and then you should be able to go run successfully.

@derekmahar

This comment has been minimized.

Copy link

derekmahar commented May 17, 2020

Thank you! That fixed the problem.

Note that go get github.com/armon/go-socks5 downloaded the package into ~/go/pkg:

derek@derek-TB350-BTC:~/Projects/go/35c6aa259cab05fd56c19ad6b0cfdd0f$ go get github.com/armon/go-socks5
derek@derek-TB350-BTC:~/Projects/go/35c6aa259cab05fd56c19ad6b0cfdd0f$ find ~/go/pkg/linux_amd64/github.com/
/home/derek/go/pkg/linux_amd64/github.com/
/home/derek/go/pkg/linux_amd64/github.com/armon
/home/derek/go/pkg/linux_amd64/github.com/armon/go-socks5.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.