Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.
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.
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.
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