Skip to content

33TU/socks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧦 socks

A lightweight, dependency-free Go implementation of SOCKS4, SOCKS4a, and soon SOCKS5, providing both client and server support.

Features

✅ SOCKS4 / SOCKS4a

  • Full client (Dialer) and server (ServeContext) implementations
  • Supports both CONNECT and BIND commands
  • 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.Context support throughout client and server code

🧩 Planned

  • SOCKS5 support (both client and server)
  • Username/password authentication
  • UDP ASSOCIATE (SOCKS5)

Quick Start

Run a SOCKS4 proxy server

go run ./cmd/socks4/main.go

By default, it listens on :1080 (TCP). You can test it using curl:

curl -v --socks4 127.0.0.1:1080 https://example.com

Example: Using the SOCKS4 Dialer

func 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)
	}
}

Project Goals

  1. Provide a clean, readable, and tested SOCKS implementation.
  2. Support both client and server use cases.
  3. No external dependencies.
  4. Be fast and correct for real-world proxy usage.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages