Skip to content

Instantly share code, notes, and snippets.

@simos
Last active November 25, 2020 06:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simos/35c6aa259cab05fd56c19ad6b0cfdd0f to your computer and use it in GitHub Desktop.
Save simos/35c6aa259cab05fd56c19ad6b0cfdd0f to your computer and use it in GitHub Desktop.
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
Copy link

@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
Copy link
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
Copy link

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