A lightweight, dependency-free Go implementation of SOCKS4, SOCKS4a, and soon SOCKS5, providing both client and server support.
- Full client (
Dialer) and server (ServeContext) implementations - Supports both
CONNECTandBINDcommands - Customizable via handler callbacks (
OnConnect,OnBind,OnRequest,OnError, etc.) - Default handlers for simple proxying and rejection logic
- Extensive tests covering end-to-end CONNECT and BIND behavior
context.Contextsupport throughout client and server code
- SOCKS5 support (both client and server)
- Username/password authentication
- UDP ASSOCIATE (SOCKS5)
go run ./cmd/socks4/main.goBy default, it listens on :1080 (TCP). You can test it using curl:
curl -v --socks4 127.0.0.1:1080 https://example.comfunc main() {
// Create a new SOCKS4 dialer (proxyAddr, userID, baseDialFunc)
dialer := socks4.NewDialer("127.0.0.1:1080", "user", nil)
// Establish a connection through the SOCKS4 proxy
conn, err := dialer.DialContext(context.Background(), "tcp", "example.com:80")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
// Send an HTTP request through the proxy
fmt.Fprintf(conn, "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n")
// Print the reply
if _, err := io.Copy(os.Stdout, conn); err != nil {
log.Fatal(err)
}
}- Provide a clean, readable, and tested SOCKS implementation.
- Support both client and server use cases.
- No external dependencies.
- Be fast and correct for real-world proxy usage.
MIT