socks

package
v0.0.188 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package socks provides SOCKS4/4a/5 protocol encoding and decoding utilities.

Index

Constants

View Source
const (
	Version4 byte = 0x04
	Version5 byte = 0x05
)

SOCKS protocol version bytes

View Source
const (
	CmdConnect      byte = 0x01
	CmdBind         byte = 0x02
	CmdUDPAssociate byte = 0x03
)

SOCKS command codes

View Source
const (
	AuthNoAuth           byte = 0x00
	AuthGSSAPI           byte = 0x01
	AuthUsernamePassword byte = 0x02
	AuthNoAcceptable     byte = 0xFF
)

SOCKS5 authentication method codes

View Source
const (
	AtypIPv4   byte = 0x01
	AtypDomain byte = 0x03
	AtypIPv6   byte = 0x04
)

SOCKS5 address type codes

View Source
const (
	RepSuccess            byte = 0x00
	RepGeneralFailure     byte = 0x01
	RepNotAllowed         byte = 0x02
	RepNetworkUnreachable byte = 0x03
	RepHostUnreachable    byte = 0x04
	RepConnectionRefused  byte = 0x05
	RepTTLExpired         byte = 0x06
	RepCmdNotSupported    byte = 0x07
	RepAtypNotSupported   byte = 0x08
)

SOCKS5 reply codes

View Source
const (
	SOCKS4RepGranted       byte = 0x5A // request granted
	SOCKS4RepRejected      byte = 0x5B // request rejected or failed
	SOCKS4RepIdentFail     byte = 0x5C // rejected: cannot connect to client's identd
	SOCKS4RepIdentMismatch byte = 0x5D // rejected: client program and identd report different user-ids
)

SOCKS4 reply codes (Ying-Da Lee spec)

View Source
const AuthUsernamePasswordVersion byte = 0x01

SOCKS5 username/password sub-negotiation version

Variables

This section is empty.

Functions

func BuildSOCKS4ConnectRequest

func BuildSOCKS4ConnectRequest(ip net.IP, port uint16, userid string) []byte

BuildSOCKS4ConnectRequest builds a SOCKS4 CONNECT request for the given IP and port. userid is the user identifier string (may be empty).

func BuildSOCKS4aConnectRequest

func BuildSOCKS4aConnectRequest(hostname string, port uint16, userid string) []byte

BuildSOCKS4aConnectRequest builds a SOCKS4a CONNECT request for the given hostname and port. SOCKS4a uses a special IP (0.0.0.0/0.0.0.1) and appends the hostname after the userid.

func BuildSOCKS5BindRequest

func BuildSOCKS5BindRequest(ip net.IP, port uint16) []byte

BuildSOCKS5BindRequest builds a SOCKS5 BIND request.

func BuildSOCKS5ConnectRequest

func BuildSOCKS5ConnectRequest(ip net.IP, port uint16) []byte

BuildSOCKS5ConnectRequest builds a SOCKS5 CONNECT request using an IPv4 address.

func BuildSOCKS5ConnectRequestDomain

func BuildSOCKS5ConnectRequestDomain(hostname string, port uint16) []byte

BuildSOCKS5ConnectRequestDomain builds a SOCKS5 CONNECT request using a domain name.

func BuildSOCKS5Greeting

func BuildSOCKS5Greeting(methods []byte) []byte

BuildSOCKS5Greeting builds a SOCKS5 client greeting offering the specified auth methods.

func BuildSOCKS5UDPAssociateRequest

func BuildSOCKS5UDPAssociateRequest(ip net.IP, port uint16) []byte

BuildSOCKS5UDPAssociateRequest builds a SOCKS5 UDP ASSOCIATE request.

func BuildSOCKS5UDPRequest

func BuildSOCKS5UDPRequest(ip net.IP, port uint16, data []byte) []byte

BuildSOCKS5UDPRequest builds a SOCKS5 UDP request encapsulation header.

func BuildSOCKS5UsernamePasswordAuth

func BuildSOCKS5UsernamePasswordAuth(username, password string) []byte

BuildSOCKS5UsernamePasswordAuth builds a SOCKS5 username/password auth sub-negotiation request.

func ParseSOCKS4Reply

func ParseSOCKS4Reply(r io.Reader) (replyCode byte, boundIP net.IP, boundPort uint16, err error)

ParseSOCKS4Reply reads and parses an 8-byte SOCKS4 reply. Returns the reply code and bound address/port.

func ParseSOCKS5AuthReply

func ParseSOCKS5AuthReply(r io.Reader) (success bool, err error)

ParseSOCKS5AuthReply reads the SOCKS5 username/password auth reply. Returns true if authentication was successful (status == 0x00).

func ParseSOCKS5Reply

func ParseSOCKS5Reply(r io.Reader) (repCode byte, bndAddr string, bndPort uint16, err error)

ParseSOCKS5Reply reads and parses a SOCKS5 reply. Returns the reply code, bound address, and bound port.

func ParseSOCKS5ServerChoice

func ParseSOCKS5ServerChoice(r io.Reader) (method byte, err error)

ParseSOCKS5ServerChoice reads the SOCKS5 server's method selection reply. Returns the chosen auth method byte.

Types

This section is empty.

Jump to

Keyboard shortcuts

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