32
socks5 - SOCKS Protocol Version 5 Library in Go. Full TCP/UDP and IPv4/IPv6 supp...
source link: https://github.com/txthinking/socks5
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
socks5
SOCKS Protocol Version 5 Library.
Full TCP/UDP and IPv4/IPv6 support. Goals: KISS, less is more, small API, code is like the original protocol.
Install
$ go get github.com/txthinking/socks5
Struct is like concept in protocol
- Negotiation:
-
type NegotiationRequest struct
func NewNegotiationRequest(methods []byte) func (r *NegotiationRequest) WriteTo(w *net.TCPConn) func NewNegotiationRequestFrom(r *net.TCPConn)
-
type NegotiationReply struct
func NewNegotiationReply(method byte) func (r *NegotiationReply) WriteTo(w *net.TCPConn) func NewNegotiationReplyFrom(r *net.TCPConn)
-
- User and password negotiation:
-
type UserPassNegotiationRequest struct
func NewUserPassNegotiationRequest(username []byte, password []byte) func (r *UserPassNegotiationRequest) WriteTo(w *net.TCPConn) func NewUserPassNegotiationRequestFrom(r *net.TCPConn)
-
type UserPassNegotiationReply struct
func NewUserPassNegotiationReply(status byte) func (r *UserPassNegotiationReply) WriteTo(w *net.TCPConn) func NewUserPassNegotiationReplyFrom(r *net.TCPConn)
-
- Request:
-
type Request struct
func NewRequest(cmd byte, atyp byte, dstaddr []byte, dstport []byte) func (r *Request) WriteTo(w *net.TCPConn) func NewRequestFrom(r *net.TCPConn)
-
- Reply:
-
type Reply struct
func NewReply(rep byte, atyp byte, bndaddr []byte, bndport []byte) func (r *Reply) WriteTo(w *net.TCPConn) func NewReplyFrom(r *net.TCPConn)
-
- Datagram:
-
type Datagram struct
func NewDatagram(atyp byte, dstaddr []byte, dstport []byte, data []byte) func NewDatagramFromBytes(bb []byte) (*Datagram, error) func (d *Datagram) Bytes() []byte
-
Advanced API
You can process client's request by yourself after reading *Request from client. Also, here is a advanced interfaces.
-
type Server struct
-
type Handler interface
TCPHandle(*Server, *net.TCPConn, *Request) error UDPHandle(*Server, *net.UDPAddr, *Datagram) error
This is example:
s, _ := NewClassicServer(addr, ip, username, password, tcpTimeout, tcpDeadline, udpDeadline, udpSessionTime) s.Run(Handler)
- If you want a standard socks5 server, pass in nil
- If you want to handle data by yourself, pass in a custom Handler
Users:
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK