socks

package module
v0.0.0-...-071591e Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2019 License: MIT Imports: 9 Imported by: 2

README

SOCKS

Build Status GoDoc

SOCKS implements SOCKS4/5 Proxy Protocol and HTTP Tunnel which can help you get through firewall. The cmd/socksd build with package SOCKS, supports cipher connection which crypto method is rc4, des, aes-128-cfb, aes-192-cfb and aes-256-cfb, upstream which can be shadowsocks or socsk5.

Install

Assume you have go installed, you can install from source.

go get github.com/eahydra/socks

If you want to install cmd/socksd, please read the README.md

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Direct = direct{}

Direct is a direct proxy which implements Dialer interface: one that makes connections directly.

Functions

This section is empty.

Types

type Dialer

type Dialer interface {
	// Dial connects to the given address via the proxy.
	Dial(network, address string) (net.Conn, error)
}

A Dialer is a means to establish a connection.

type HTTPProxy

type HTTPProxy struct {
	*httputil.ReverseProxy
	// contains filtered or unexported fields
}

HTTPProxy is an HTTP Handler that serve CONNECT method and route request to proxy server by Router.

func NewHTTPProxy

func NewHTTPProxy(forward Dialer) *HTTPProxy

NewHTTPProxy constructs one HTTPProxy

func (*HTTPProxy) ServeHTTP

func (h *HTTPProxy) ServeHTTP(response http.ResponseWriter, request *http.Request)

ServeHTTP implements HTTP Handler

func (*HTTPProxy) ServeHTTPTunnel

func (h *HTTPProxy) ServeHTTPTunnel(response http.ResponseWriter, request *http.Request)

ServeHTTPTunnel serve incoming request with CONNECT method, then route data to proxy server

type ShadowSocksClient

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

ShadowSocksClient implements ShadowSocks Proxy Protocol

func NewShadowSocksClient

func NewShadowSocksClient(network, address string, forward Dialer) (*ShadowSocksClient, error)

NewShadowSocksClient return a new ShadowSocksClient that implements Dialer interface.

func (*ShadowSocksClient) Dial

func (s *ShadowSocksClient) Dial(network, address string) (net.Conn, error)

Dial return a new net.Conn that through proxy server establish with address

type Socks4Client

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

Socks4Client implements Socks4 Proxy Protocol(http://www.openssh.com/txt/socks4.protocol).

Example
user := ""
client, err := NewSocks4Client("tcp", "127.0.0.1:1080", user, Direct)
if err != nil {
	return
}
addrs, err := net.LookupHost("www.google.com")
if err != nil {
	return
}
if len(addrs) == 0 {
	return
}
conn, err := client.Dial("tcp", addrs[0]+":80")
if err != nil {
	return
}
httpClient := httputil.NewClientConn(conn, nil)
defer httpClient.Close()

request, err := http.NewRequest("GET", "/", nil)
if err != nil {
	return
}
resp, err := httpClient.Do(request)
if err != nil {
	return
}
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
	return
}
println(string(dump))
return
Output:

func NewSocks4Client

func NewSocks4Client(network, address, userID string, forward Dialer) (*Socks4Client, error)

NewSocks4Client return a new Socks4Client that implements Dialer interface. network must be supported by forward, address is proxy server's address, userID can empty.

func (*Socks4Client) Dial

func (s *Socks4Client) Dial(network, address string) (net.Conn, error)

Dial return a new net.Conn if succeeded. network must be tcp, tcp4 or tcp6, address only is IPV4.

type Socks4Server

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

Socks4Server implements Socks4 Proxy Protocol(http://www.openssh.com/txt/socks4.protocol). Just support CONNECT command.

Example
listener, err := net.Listen("tcp", ":1080")
if err != nil {
	return
}
defer listener.Close()

if server, err := NewSocks4Server(Direct); err == nil {
	server.Serve(listener)
}
Output:

func NewSocks4Server

func NewSocks4Server(forward Dialer) (*Socks4Server, error)

NewSocks4Server returns a new Socks4Server that can serve from new clients.

func (*Socks4Server) Serve

func (s *Socks4Server) Serve(listener net.Listener) error

Serve with net.Listener for clients.

type Socks5Client

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

Socks5Client implements Socks5 Proxy Protocol(RFC 1928) Client Protocol. Just support CONNECT command, and support USERNAME/PASSWORD authentication methods(RFC 1929)

Example
user := ""
password := ""
client, err := NewSocks5Client("tcp", "127.0.0.1:1080", user, password, Direct)
if err != nil {
	return
}
conn, err := client.Dial("tcp", "www.google.com:80")
if err != nil {
	return
}
httpClient := httputil.NewClientConn(conn, nil)
defer httpClient.Close()

request, err := http.NewRequest("GET", "/", nil)
if err != nil {
	return
}
resp, err := httpClient.Do(request)
if err != nil {
	return
}
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
	return
}
println(string(dump))
return
Output:

func NewSocks5Client

func NewSocks5Client(network, address, user, password string, forward Dialer) (*Socks5Client, error)

NewSocks5Client return a new Socks5Client that implements Dialer interface.

func (*Socks5Client) Dial

func (s *Socks5Client) Dial(network, address string) (net.Conn, error)

Dial return a new net.Conn that through the CONNECT command to establish connections with proxy server. address as RFC's requirements that can be IPV4, IPV6 and domain host, such as 8.8.8.8:999 or google.com:80

type Socks5Server

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

Socks5Server implements Socks5 Proxy Protocol(RFC 1928), just support CONNECT command.

Example
listener, err := net.Listen("tcp", ":1080")
if err != nil {
	return
}
defer listener.Close()

if server, err := NewSocks5Server(Direct); err == nil {
	server.Serve(listener)
}
Output:

func NewSocks5Server

func NewSocks5Server(forward Dialer) (*Socks5Server, error)

NewSocks5Server return a new Socks5Server

func (*Socks5Server) Serve

func (s *Socks5Server) Serve(listener net.Listener) error

Serve with net.Listener for new incoming clients.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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