hsocks5

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: MIT Imports: 22 Imported by: 0

README

HSocks5

GitHub Workflow Status CircleCI codecov Quality Gate Status Total alerts

Docker Cloud Build Status Docker Image Size (tag)

Provide HTTP Proxy based on Socks5 Proxy.

This project is the golang version of the tool http-proxy-to-socks, with much faster processing & less memory taking.

Why?

Most operation systems (like windows, android & iOS) only support HTTP Proxy without other tools, if users want to use a socks5 proxy, users must install some app on device, but sometimes there are some limitation on the devices. This project can transform socks5 proxy into http proxy, so that make all devices can connect with the socks5 proxy.

Setup with binary

Download pre-built binaries from here. (you should download the correct binary for your platform)

And run with

./hsocks5 --socks 192.168.3.88:10080 start

Setup with docker

Run this tool with docker

docker run --restart=always -d -p 18080:18080 -e SOCKS=192.168.3.88:10080 --name hsocks5 thedockerimages/hsocks5:latest

The 192.168.3.88:10080 is the socks5 server host and port.

The 18080 is the http proxy default port, you can use docker expose it as another port.

Options

./hsocks5 --help

NAME:
   HSocks5 - provide HTTP Proxy with Socks5

USAGE:
   hsocks5 [global options] command [command options] [arguments...]

VERSION:
   SNAPSHOT

COMMANDS:
   start    program entry
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --addr value, -a value   HTTP proxy listen address (default: ":18080") [%ADDR%]
   --socks value, -s value  Socks5 service url, format: hostname:port, 192.168.1.1:18080 [%SOCKS%]
   --redis value, -r value  Redis cache for proxy check [%REDIS_SERVER%]
   --china-switchy          For mainland china user, 'hsocks' can automatic use 'socks5 proxy' ondemand [%CHINA_SWITCHY%]
   --help, -h               show help
   --version, -v            print the versio

Prometheus metric

HSocks5 exposes prometheus metric endpoint at /hsocks5/__/metric

CHANGELOG

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets. nolint: deadcode

func Copy added in v0.1.0

func Copy(dst io.Writer, src io.Reader) (written int64, err error)

Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.

A successful Copy returns err == nil, not err == EOF. Because Copy is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

If src implements the WriterTo interface, the copy is implemented by calling src.WriteTo(dst). Otherwise, if dst implements the ReaderFrom interface, the copy is implemented by calling dst.ReadFrom(src).

func CopyBuffer added in v0.1.0

func CopyBuffer(dst io.Writer, src io.Reader, buf []byte) (written int64, err error)

CopyBuffer is identical to Copy except that it stages through the provided buffer (if one is required) rather than allocating a temporary one. If buf is nil, one is allocated; otherwise if it has zero length, CopyBuffer panics.

If either src implements WriterTo or dst implements ReaderFrom, buf will not be used to perform the copy.

func LoadGFWList

func LoadGFWList() *adblock.RuleMatcher

LoadGFWList file

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables. nolint: deadcode

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

Types

type IPList

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

IPList type

func LoadIPListFrom

func LoadIPListFrom(path string) *IPList

LoadIPListFrom assets

func NewIPList

func NewIPList(cidrs string) *IPList

NewIPList object

func (*IPList) Contains

func (l *IPList) Contains(ipOrHostname string) (rt bool)

Contains ip in IPList

func (*IPList) ContainsIP

func (l *IPList) ContainsIP(ip net.IP) (rt bool)

ContainsIP value

func (*IPList) MultiContains

func (l *IPList) MultiContains(ipOrHostnames []string) (rt bool)

MultiContains any on any in IPList

func (*IPList) MultiContainsIPs

func (l *IPList) MultiContainsIPs(ips []net.IP) (rt bool)

MultiContainsIPs value

type KVCache added in v0.0.3

type KVCache struct {
	Set     func(string, string)
	Get     func(string) (string, bool)
	MustGet func(string) string
	// contains filtered or unexported fields
}

KVCache type

func NewKVCache added in v0.0.3

func NewKVCache(redisAddr ...string) (rt *KVCache)

NewKVCache instance

type KeyLock added in v0.0.5

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

KeyLock type

func NewKeyLock added in v0.0.5

func NewKeyLock() *KeyLock

NewKeyLock instance

func (*KeyLock) GetLock added in v0.0.5

func (kl *KeyLock) GetLock(key string) *sync.Mutex

GetLock by key

func (*KeyLock) Lock added in v0.0.5

func (kl *KeyLock) Lock(key string)

Lock by key

func (*KeyLock) Unlock added in v0.0.5

func (kl *KeyLock) Unlock(key string)

Unlock by key

type ProxyServer

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

ProxyServer class

func NewProxyServer

func NewProxyServer(option *ProxyServerOption) (*ProxyServer, error)

NewProxyServer object

func (*ProxyServer) ServeHTTP

func (s *ProxyServer) ServeHTTP(res http.ResponseWriter, req *http.Request)

func (*ProxyServer) Start

func (s *ProxyServer) Start() error

Start server

type ProxyServerMetrics

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

ProxyServerMetrics class

func NewProxyServerMetrics

func NewProxyServerMetrics() (rt *ProxyServerMetrics)

NewProxyServerMetrics constructor

func (*ProxyServerMetrics) AddErrorMetric added in v0.0.6

func (m *ProxyServerMetrics) AddErrorMetric(category, context string)

AddErrorMetric count

type ProxyServerOption added in v0.0.5

type ProxyServerOption struct {
	ListenAddr  string
	RedisAddr   string
	SocksAddr   string
	ChinaSwitch bool
	// provided dialer, will prefer use this programming dialer instead of socks5 service
	Dialer proxy.Dialer
}

ProxyServerOption parameter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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