ProxyConnector

package module
v0.0.0-...-7e11129 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: GPL-3.0 Imports: 19 Imported by: 0

README

Usage

// 
//  support vmess / ss / ssr / socks 
//

if dialer := NewProxyDialer("vmess://..."); dialer != nil{
        dialer.Dial("tcp",target)
}


// http:

if client := ProxyConnector.NewProxyHttpClient("ssr://...."); client != nil {
        client.Get("https://www.google.com")
}


Example



package main

import (
        "flag"
        "fmt"
        "log"
        "strings"
        "sync"
        "time"

        "github.com/Qingluan/ProxyConnector"
)

func main() {
        var testurlorder string
        var url string
        flag.StringVar(&testurlorder, "o", "", "order url or ssr/ss uri")
        flag.StringVar(&url, "u", "", "target test")
        flag.Parse()

        if url == "" {
                url = "https://www.google.com"
        }
        var wait sync.WaitGroup
        if testurlorder != "" && strings.HasPrefix(testurlorder, "http") {
                for _, ssurl := range ProxyConnector.ParserOrder(testurlorder) {
                        fmt.Println(ssurl)
                        wait.Add(1)
                        go func(url string, ssurl string) {
                                defer wait.Done()
                                if client := ProxyConnector.NewProxyHttpClient(ssurl); client != nil {
                                        st := time.Now()
                                        if res, err := client.Get(url); err != nil {
                                                log.Println("used:", time.Now().Sub(st), "err:", err)
                                        } else {
                                                log.Println("used:", time.Now().Sub(st), "code:", res.StatusCode, "proxy:", ProxyConnector.MustParseUri(ssurl))
                                        }
                                }

                        }(url, ssurl)
                }
                wait.Wait()
        } else {
                if client := ProxyConnector.NewProxyHttpClient(testurlorder); client != nil {
                        st := time.Now()
                        if res, err := client.Get(url); err != nil {
                                log.Println("used:", time.Now().Sub(st), "err:", err)
                        } else {
                                log.Println("used:", time.Now().Sub(st), "code:", res.StatusCode, "proxy:", ProxyConnector.MustParseUri(testurlorder))
                        }
                }
        }
}


Documentation

Index

Constants

View Source
const (
	Random = 1
	Flow   = 0
)

Variables

View Source
var (
	ParseOrder = config.ParseOrding
	ParseUri   = func(uri string) (cfg config.Config, err error) {
		if strings.HasPrefix(uri, "vmess://") {
			return config.ParseVmessUri(uri)
		} else if strings.HasPrefix(uri, "ss") {
			return config.ParseSSUri(uri)
		} else {
			return cfg, errors.New("Invalid uri:" + uri)
		}
	}
	MustParseUri = func(uri string) (cfg config.Config) {
		var e error
		if strings.HasPrefix(uri, "vmess://") {
			cfg, e = config.ParseVmessUri(uri)
		} else if strings.HasPrefix(uri, "ss") {
			cfg, e = config.ParseSSUri(uri)
		} else {
			return cfg
		}
		if e != nil {
			log.Fatal("parse uri:", e, uri)
		}
		return cfg
	}
)
View Source
var (
	DefaultProxyPool = NewProxyPool()
)
View Source
var (
	DefaultTimeout = 12
)
View Source
var (
	OrderHistory = map[string]*ProxyPool{}
)

Functions

func ArraiExists

func ArraiExists(arr []string, o string) bool

func ChooiceOne

func ChooiceOne(array []interface{}) interface{}

func NewProxyDialer

func NewProxyDialer(proxyObj interface{}) (dialer proxy.Dialer)

func NewProxyHttpClient

func NewProxyHttpClient(proxy interface{}, timeout ...int) (client *http.Client)

func Socks5Dialer

func Socks5Dialer(addr string) proxy.Dialer

Types

type Dialer

type Dialer interface {
	Dial(network, addr string) (net.Conn, error)
	ToHttpClient(timeout ...int) (client *http.Client)
	ProxyURI() string
}

type ProgressBar

type ProgressBar interface {
	Add(i int) int
	Increment() int
	Update()
}

type ProxyDialer

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

func NewDialer

func NewDialer(ssconf config.Config) (dialer *ProxyDialer, err error)

func NewDialerByURI

func NewDialerByURI(ssuri string) (dialer *ProxyDialer, err error)

func (*ProxyDialer) Dial

func (ss *ProxyDialer) Dial(network string, addr string) (con net.Conn, err error)

func (*ProxyDialer) ProxyURI

func (dialer *ProxyDialer) ProxyURI() string

func (*ProxyDialer) ToHttpClient

func (proxy *ProxyDialer) ToHttpClient(timeout ...int) (client *http.Client)

type ProxyPool

type ProxyPool struct {
	Mode int
	// contains filtered or unexported fields
}

func NewProxyPool

func NewProxyPool(url ...string) (proxyPool *ProxyPool)

NewProxyPool can set mode pool.Mode = Random / pool.Mode = Flow (default is flow)

func (*ProxyPool) Add

func (proxyPool *ProxyPool) Add(url string)

func (*ProxyPool) Adds

func (proxyPool *ProxyPool) Adds(urls []string)

func (*ProxyPool) Count

func (proxyPool *ProxyPool) Count() int

func (*ProxyPool) Empty

func (proxyPool *ProxyPool) Empty() bool

func (*ProxyPool) Get

func (pool *ProxyPool) Get() (outuri string)

func (*ProxyPool) LoopOneTurn

func (pool *ProxyPool) LoopOneTurn(doWhat func(proxyDialer Dialer) interface{}, processor ...ProgressBar) (o map[string]interface{})

func (*ProxyPool) Merge

func (pool *ProxyPool) Merge(ppool ProxyPool)

func (*ProxyPool) Urls

func (proxyPool *ProxyPool) Urls() (urls []string)

type Result

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

Directories

Path Synopsis
shadowsocks
ssr
tools/leakybuf
Provides leaky buffer, based on the example in Effective Go.
Provides leaky buffer, based on the example in Effective Go.
tools/socks
Package socks implements essential parts of SOCKS protocol.
Package socks implements essential parts of SOCKS protocol.
Package ws implements a simple websocket client.
Package ws implements a simple websocket client.

Jump to

Keyboard shortcuts

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