socksproxy

package
v0.0.0-...-1db1413 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package socksproxy implements essential parts of SOCKS protocol.

Index

Examples

Constants

View Source
const (
	CmdConnect      = 1
	CmdBind         = 2
	CmdUDPAssociate = 3
)

SOCKS request commands as defined in RFC 1928 section 4.

View Source
const (
	AtypIPv4       = 1
	AtypDomainName = 3
	AtypIPv6       = 4
)

SOCKS address types as defined in RFC 1928 section 5.

View Source
const (
	ErrGeneralFailure       = Error("ErrGeneralFailure")
	ErrConnectionNotAllowed = Error("ErrConnectionNotAllowed")
	ErrNetworkUnreachable   = Error("ErrNetworkUnreachable")
	ErrHostUnreachable      = Error("ErrHostUnreachable")
	ErrConnectionRefused    = Error("ErrConnectionRefused")
	ErrTTLExpired           = Error("ErrTTLExpired")
	ErrCommandNotSupported  = Error("ErrCommandNotSupported")
	ErrAddressNotSupported  = Error("ErrAddressNotSupported")
	InfoUDPAssociate        = Error("InfoUDPAssociate")
)

SOCKS errors as defined in RFC 1928 section 6.

View Source
const MaxAddrLen = 1 + 1 + 255 + 2

MaxAddrLen is the maximum size of SOCKS address in bytes.

Variables

View Source
var UDPEnabled = true

UDPEnabled is the toggle for UDP support

Functions

This section is empty.

Types

type Error

type Error string

Error represents a SOCKS error

func (Error) Error

func (err Error) Error() string

type Socks5Addr

type Socks5Addr struct {
	Raw     []byte
	AType   int
	Address string
	Port    int
}

Socks5Addr represents a SOCKS address as defined in RFC 1928 section 5.

func NewSSProtocol

func NewSSProtocol(atype, port int, address string) *Socks5Addr

func NewSocks5Addr

func NewSocks5Addr(raw []byte, atype int) *Socks5Addr

func ParseAddr

func ParseAddr(s string) *Socks5Addr

ParseAddr parses the address in string s. Returns nil if failed.

func ReadAddr

func ReadAddr(r io.Reader) (*Socks5Addr, error)

ReadAddr reads just enough bytes from r to get a valid Addr.

func SplitAddr

func SplitAddr(b []byte) (*Socks5Addr, error)

SplitAddr slices a SOCKS address from beginning of b. Returns nil if failed.

func (*Socks5Addr) GetAType

func (s *Socks5Addr) GetAType() int

func (*Socks5Addr) GetAddress

func (s *Socks5Addr) GetAddress() string

func (*Socks5Addr) GetPort

func (s *Socks5Addr) GetPort() int

func (*Socks5Addr) GetRaw

func (ss *Socks5Addr) GetRaw() (raw []byte, err error)
Example
fmt.Printf("%v\n", utils.NewSSProtocol(utils.AtypIPv4, 3306, "127.0.0.1").MustGetRaw())
ss := utils.SplitAddr(utils.NewSSProtocol(utils.AtypIPv4, 3306, "127.0.0.1").MustGetRaw())
if ss == nil {
	fmt.Println("ss is null")
}
fmt.Printf("%v\n", ss.MustGetRaw())

fmt.Printf("%v\n", utils.NewSSProtocol(utils.AtypDomainName, 3306, "baidu.com").MustGetRaw())
ss = utils.SplitAddr(utils.NewSSProtocol(utils.AtypDomainName, 3306, "baidu.com").MustGetRaw())
if ss == nil {
	fmt.Println("ss is null")
}
fmt.Printf("%v\n", ss.MustGetRaw())
Output:

[1 127 0 0 1 12 234]
[1 127 0 0 1 12 234]
[3 9 98 97 105 100 117 46 99 111 109 12 234]
[3 9 98 97 105 100 117 46 99 111 109 12 234]

func (*Socks5Addr) MustGetRaw

func (ss *Socks5Addr) MustGetRaw() []byte

func (*Socks5Addr) String

func (s *Socks5Addr) String() string

Jump to

Keyboard shortcuts

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