socks5

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2024 License: MIT Imports: 15 Imported by: 0

README

Gopher socks logo

SOCKS 5

license go version go doc go report tests

Report Bug | Request Feature

A fully featured implementation of the SOCKS 5 protocol in golang.

CONNECT BIND UDP ASSOCIATE
✅ - implemented 🛠 - in progress ✅ - implemented
Gopher socks logo

Installation

go get github.com/JC5LZiy3HVfV5ux/socks5

Getting Started

Create your .go file. For example: main.go.

package main

import (
	"context"
	"log"
	"os"
	"os/signal"

	"github.com/JC5LZiy3HVfV5ux/socks5"
)

func main() {
	ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
	defer stop()

	srv := socks5.New()

	go func() {
		if err := srv.ListenAndServe(); err != nil {
			log.Fatal(err)
		}
	}()

	<-ctx.Done()

	if err := srv.Shutdown(); err != nil {
		log.Fatal(err)
	}
}

Run your server:

go run main.go

The following curl example shows how to use the proxy server:

curl -x socks5://127.0.0.1:1080 http://example.com

See the tests for more information about package.

FAQ

  • Why can't connect to socks proxy server?

    Not all applications and browsers support socks authentication or socks protocol. You may need extension for Chrome or another browser. The proof of work for the UDP association was done using qBittorrent - a BitTorrent client.

If you have any questions, you can ask in GitHub Discussions.

References

  • RFC 1928 SOCKS Protocol Version 5
  • RFC 1929 Username/Password Authentication for SOCKS V5

Licenses

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NopLogger *nopLogger

Silent logger, produces no output

Functions

func RemoteAddressFromContext

func RemoteAddressFromContext(ctx context.Context) (string, bool)

func UsernameFromContext added in v0.5.0

func UsernameFromContext(ctx context.Context, username string) (string, bool)

Types

type Driver

type Driver interface {
	Listen(network, address string) (net.Listener, error)
	ListenPacket(network, address string) (net.PacketConn, error)
	Dial(network, address string) (net.Conn, error)
}

type Logger

type Logger interface {
	Info(ctx context.Context, msg string, args ...any)
	Warn(ctx context.Context, msg string, args ...any)
	Error(ctx context.Context, msg string, args ...any)
}

type Metrics added in v0.5.0

type Metrics interface {
	UploadBytes(ctx context.Context, n int64)
	DownloadBytes(ctx context.Context, n int64)
}

type Option added in v0.7.0

type Option func(*options)

func WithDialTimeout added in v0.7.0

func WithDialTimeout(val time.Duration) Option

func WithDriver added in v0.7.0

func WithDriver(val Driver) Option

func WithGetPasswordTimeout added in v0.7.0

func WithGetPasswordTimeout(val time.Duration) Option

func WithHost added in v0.7.0

func WithHost(val string) Option

func WithLogger added in v0.7.0

func WithLogger(val Logger) Option

func WithMetrics added in v0.7.0

func WithMetrics(val Metrics) Option

func WithPasswordAuthentication added in v0.7.0

func WithPasswordAuthentication() Option

func WithPort added in v0.7.0

func WithPort(val int) Option

func WithPublicIP added in v0.7.0

func WithPublicIP(val net.IP) Option

func WithReadTimeout added in v0.7.0

func WithReadTimeout(val time.Duration) Option

func WithStaticCredentials added in v0.7.0

func WithStaticCredentials(val map[string]string) Option

func WithStore added in v0.7.0

func WithStore(val Store) Option

func WithWriteTimeout added in v0.7.0

func WithWriteTimeout(val time.Duration) Option

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) Shutdown

func (s *Server) Shutdown() error

type Store

type Store interface {
	GetPassword(ctx context.Context, username string) (string, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL