Documentation ¶
Overview ¶
Package socks5
SOCKS protocol version 5 is defined in RFC 1928. Username/Password authentication for SOCKS version 5 is defined in RFC 1929.
Index ¶
- Constants
- func ClientHandshake(conn net.Conn, hostPort string, cmd byte, auths []AuthMethod) error
- func ClientHandshakeTimeout(conn net.Conn, hostPort string, cmd byte, auths []AuthMethod, ...) error
- func Dial(network, address, hostPort string, auths []AuthMethod) (net.Conn, error)
- func DialTimeout(network, address, hostPort string, auths []AuthMethod, timeout time.Duration) (net.Conn, error)
- func ParseHostPort(addrType byte, addr []byte, port []byte) (hostPort string, err error)
- func ServerHandshake(conn net.Conn, auths []AuthMethod) (hostPort string, err error)
- func ServerHandshakeTimeout(conn net.Conn, auths []AuthMethod, timeout time.Duration) (hostPort string, err error)
- type AuthMethod
- type AuthNone
- type AuthUserPassword
- type AuthUserPasswordServer
- type HelloRequest
- type HelloResponse
- type Listener
- type ReplyCode
- type Request
- type Response
Constants ¶
const ( UserPasswordVer = 0x01 UserPasswordSuccess = 0x00 UserPasswordFailure = 0x01 )
const ( Version = 0x05 // SOCKS Protocol version 5 AuthMethodNone = 0x00 // No authentication required AuthMethodGSSAPI = 0x01 // GSSAPI AuthMethodUserPassword = 0x02 // Username/Password AuthMethodNoAcceptableMethods = 0xFF // No acceptable method AddrTypeIPv4 = 0x01 // 1 for IPv4 address AddrTypeDomain = 0x03 // 3 for domain name AddrTypeIPv6 = 0x04 // 4 for IPv6 address CmdConnect = 0x01 // establish a TCP/IP stream connection CmdBind = 0x02 // associate a name with a socket todo CmdUdpAssociate = 0x03 // establish a UDP association todo StatusSucceeded = 0x00 // succeeded )
Variables ¶
This section is empty.
Functions ¶
func ClientHandshake ¶
ClientHandshake client执行socks5握手,
func ClientHandshakeTimeout ¶
func ClientHandshakeTimeout(conn net.Conn, hostPort string, cmd byte, auths []AuthMethod, timeout time.Duration) error
ClientHandshakeTimeout client设置超时时间并执行socks5握手
func Dial ¶
func Dial(network, address, hostPort string, auths []AuthMethod) (net.Conn, error)
Dial 使用给定的network、address连接到远程主机, hostPort为要代理的地址, auths为支持的认证方法, nil则使用AuthNone
func DialTimeout ¶
func DialTimeout(network, address, hostPort string, auths []AuthMethod, timeout time.Duration) (net.Conn, error)
DialTimeout 使用给定的network、address连接到远程主机, 并设置超时时间, hostPort为要代理的地址, auths为支持的认证方法, nil则使用AuthNone
func ParseHostPort ¶
ParseHostPort 通过addrType解析addr和port,转换为host:port格式
func ServerHandshake ¶
func ServerHandshake(conn net.Conn, auths []AuthMethod) (hostPort string, err error)
ServerHandshake server执行socks5握手, 握手成功返回client请求的hostPort ServerHandshake无论握手成功与否, 都不会发送Response数据, 需要用户自动构造Response回复
func ServerHandshakeTimeout ¶
func ServerHandshakeTimeout(conn net.Conn, auths []AuthMethod, timeout time.Duration) (hostPort string, err error)
ServerHandshakeTimeout server设置超时时间执行socks5握手, 握手成功返回client请求的hostPort ServerHandshakeTimeout无论握手成功与否, 都不会发送Response数据, 需要用户自动构造Response回复
Types ¶
type AuthMethod ¶
type AuthMethod interface { // Method return method byte Method() byte // Auth 认证具体实现 // 如果 error 为 nil, 表示认证成功 Auth(rw io.ReadWriter) error }
AuthMethod socks5 认证方式接口
type AuthUserPassword ¶
AuthUserPassword 客户端用户名和密码认证
func NewAuthUserPassword ¶
func NewAuthUserPassword(user, password string) *AuthUserPassword
NewAuthUserPassword create AuthUserPassword by user and password
func (*AuthUserPassword) Auth ¶
func (a *AuthUserPassword) Auth(rw io.ReadWriter) error
func (*AuthUserPassword) Method ¶
func (a *AuthUserPassword) Method() byte
type AuthUserPasswordServer ¶
type AuthUserPasswordServer struct { // map[user]password Map map[string]string // 认证失败,是否回复客户端 Reply bool }
AuthUserPasswordServer 服务端用户名和密码认证
func NewAuthUserPasswordServer ¶
func NewAuthUserPasswordServer(m map[string]string, reply bool) *AuthUserPasswordServer
NewAuthUserPasswordServer create AuthUserPasswordServer by map[user]password
func (*AuthUserPasswordServer) Auth ¶
func (a *AuthUserPasswordServer) Auth(rw io.ReadWriter) error
func (*AuthUserPasswordServer) Method ¶
func (a *AuthUserPasswordServer) Method() byte
type HelloRequest ¶
HelloRequest is the hello request packet
func (*HelloRequest) Size ¶
func (hr *HelloRequest) Size() int
type HelloResponse ¶
func (*HelloResponse) Size ¶
func (hr *HelloResponse) Size() int
type Listener ¶
A Listener is a generic network listener for socks5 protocols. Multiple goroutines may invoke methods on a Listener simultaneously.
func Listen ¶
func Listen(network, address string, auths []AuthMethod) (*Listener, error)
Listen creates a Socks5 listener accepting connections on the given network address using net.Listen. A nil auths as equivalent to the AuthNone.
func ListenTimeout ¶
func ListenTimeout(network, address string, auths []AuthMethod, timeout time.Duration) (*Listener, error)
ListenTimeout creates a Socks5 listener accepting connections on the given network address using net.Listen. A nil auths as equivalent to the AuthNone. i/o timeout will happen if client don't complete the handshake within the timeout.
type Request ¶
type Request struct { Ver byte Cmd byte Rsv byte // 0x00 AddrType byte DstAddr []byte DstPort []byte // 2 bytes }
Request is the request packet