netx

package
v1.2.6-sp8 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SOCKS4 = iota
	SOCKS4A
	SOCKS5
)

Constants to choose which version of SOCKS protocol to use.

View Source
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"

Variables

View Source
var DefaultCustomDNSServers = []string{
	"223.5.5.5", "223.6.6.6",
	"120.53.53.53", "1.1.1.1",
	"8.8.8.8",
}
View Source
var DefaultCustomDoHServers = []string{

	"https://223.5.5.5/resolve",
	"https://223.6.6.6/resolve",

	"https://1.12.12.12/dns-query",
	"https://120.53.53.53/dns-query",

	"https://1.1.1.1/dns-query",
	"https://8.8.8.8/resolve",
	"https://8.8.4.4/resolve",
}

Functions

func AddHost

func AddHost(host string, ip string)

func DialAutoGMTLSContextWithoutProxy

func DialAutoGMTLSContextWithoutProxy(ctx context.Context, network, addr string) (net.Conn, error)

DialAutoGMTLSContextWithoutProxy dials a GMTLS connection with a context.

func DialContext added in v1.2.5

func DialContext(ctx context.Context, target string, proxies ...string) (net.Conn, error)

func DialContextWithoutProxy

func DialContextWithoutProxy(ctx context.Context, network, addr string) (net.Conn, error)

DialContextWithoutProxy dials a connection with a context.

func DialForceGMTLSContextWithoutProxy

func DialForceGMTLSContextWithoutProxy(ctx context.Context, network, addr string) (net.Conn, error)

DialForceGMTLSContextWithoutProxy dials a GMTLS connection with a context.

func DialSocksProxy

func DialSocksProxy(socksType int, proxy string, username string, password string) func(string, string) (net.Conn, error)

DialSocksProxy returns the dial function to be used in http.Transport object. Argument socksType should be one of SOCKS4, SOCKS4A and SOCKS5. Argument proxy should be in this format "127.0.0.1:1080".

func DialTCPTimeout

func DialTCPTimeout(timeout time.Duration, target string, proxies ...string) (net.Conn, error)

DialTCPTimeout dial tcp with timeout

1. if no proxy, dial directly, timeout for

func DialTCPTimeoutForceProxy

func DialTCPTimeoutForceProxy(timeout time.Duration, target string, proxy string) (net.Conn, error)

func DialTLSContextWithoutProxy

func DialTLSContextWithoutProxy(ctx context.Context, network, addr string, tlsConfig *tls.Config) (net.Conn, error)

DialTLSContextWithoutProxy dials a TLS connection with a context.

func DialTLSTimeout

func DialTLSTimeout(timeout time.Duration, target string, tlsConfig any, proxy ...string) (net.Conn, error)

func DialTimeout

func DialTimeout(connectTimeout time.Duration, target string, proxy ...string) (net.Conn, error)

func DialTimeoutWithoutProxy

func DialTimeoutWithoutProxy(timeout time.Duration, network, addr string) (net.Conn, error)

DialTimeoutWithoutProxy dials a connection with a timeout.

func DialX added in v1.2.6

func DialX(target string, opt ...DialXOption) (net.Conn, error)

DialX is netx dial with more options

Proxy is a list of proxy servers, if empty, no proxy will be used, otherwise retry with each proxy until success (no redirect)

func FixProxy

func FixProxy(i string) string

func GetDefaultHostsFilePath

func GetDefaultHostsFilePath() string

func GetHost

func GetHost(host string) (ip string, ok bool)

func GetProxyFromEnv

func GetProxyFromEnv() string

func IsExistedHost

func IsExistedHost(host string) bool

func IsTLSService

func IsTLSService(addr string, proxies ...string) bool

func LoadCertificatesConfig added in v1.2.7

func LoadCertificatesConfig(i any) error

func LoadHostsFromFile

func LoadHostsFromFile(p string) error

LoadHostsFromFile loads hosts file

func LoadP12Bytes added in v1.2.7

func LoadP12Bytes(p12bytes []byte, password string) error

func LookupAll

func LookupAll(host string, opt ...DNSOption) []string

func LookupCallback

func LookupCallback(host string, h func(dnsType, domain, ip, fromServer string, method string), opt ...DNSOption) error

func LookupFirst

func LookupFirst(host string, opt ...DNSOption) string

func NewDefaultHTTPClient added in v1.2.6

func NewDefaultHTTPClient(
	proxy ...string,
) *http.Client

func NewDialContextFunc

func NewDialContextFunc(timeout time.Duration, opts ...DNSOption) func(ctx context.Context, network string, addr string) (net.Conn, error)

NewDialContextFunc is a function that can be used to dial a connection.

func NewDialGMTLSContextFunc

func NewDialGMTLSContextFunc(enableGM bool, preferGMTLS bool, onlyGMTLS bool, timeout time.Duration, opts ...DNSOption) func(ctx context.Context, network string, addr string) (net.Conn, error)

func SetDefaultOptions

func SetDefaultOptions(opt ...DNSOption)

func UpgradeToTLSConnection

func UpgradeToTLSConnection(conn net.Conn, sni string, i any) (net.Conn, error)

func UpgradeToTLSConnectionWithTimeout added in v1.2.6

func UpgradeToTLSConnectionWithTimeout(conn net.Conn, sni string, i any, timeout time.Duration) (net.Conn, error)

Types

type DNSOption

type DNSOption func(*ReliableDNSConfig)

func GetDefaultOptions

func GetDefaultOptions() []DNSOption

func WithDNSCallback

func WithDNSCallback(cb func(dnsType, domain, ip, fromServer, method string)) DNSOption

func WithDNSContext

func WithDNSContext(ctx context.Context) DNSOption

func WithDNSDisableSystemResolver

func WithDNSDisableSystemResolver(b bool) DNSOption

func WithDNSFallbackDoH

func WithDNSFallbackDoH(b bool) DNSOption

func WithDNSFallbackSpecificDNS

func WithDNSFallbackSpecificDNS(b bool) DNSOption

func WithDNSFallbackTCP

func WithDNSFallbackTCP(b bool) DNSOption

func WithDNSNoCache

func WithDNSNoCache(b bool) DNSOption

func WithDNSOnFinished added in v1.2.6

func WithDNSOnFinished(cb func()) DNSOption

func WithDNSPreferDoH

func WithDNSPreferDoH(b bool) DNSOption

func WithDNSPreferTCP

func WithDNSPreferTCP(b bool) DNSOption

func WithDNSRetryTimes

func WithDNSRetryTimes(i int) DNSOption

func WithDNSServers

func WithDNSServers(s ...string) DNSOption

func WithDNSSpecificDoH

func WithDNSSpecificDoH(s ...string) DNSOption

func WithTemporaryHosts

func WithTemporaryHosts(i map[string]string) DNSOption

func WithTimeout

func WithTimeout(timeout time.Duration) DNSOption

type DialXOption added in v1.2.6

type DialXOption func(c *dialXConfig)

func DialX_Debug added in v1.2.7

func DialX_Debug(b bool) DialXOption

func DialX_WithDNSOptions added in v1.2.6

func DialX_WithDNSOptions(opt ...DNSOption) DialXOption

func DialX_WithGMTLSConfig added in v1.2.6

func DialX_WithGMTLSConfig(config *gmtls.Config) DialXOption

func DialX_WithGMTLSOnly added in v1.2.6

func DialX_WithGMTLSOnly(b bool) DialXOption

func DialX_WithGMTLSPrefer added in v1.2.6

func DialX_WithGMTLSPrefer(b bool) DialXOption

func DialX_WithGMTLSSupport added in v1.2.6

func DialX_WithGMTLSSupport(b bool) DialXOption

func DialX_WithProxy added in v1.2.6

func DialX_WithProxy(proxy ...string) DialXOption

func DialX_WithSNI added in v1.2.6

func DialX_WithSNI(sni string) DialXOption

func DialX_WithTLS added in v1.2.6

func DialX_WithTLS(b bool) DialXOption

func DialX_WithTLSConfig added in v1.2.6

func DialX_WithTLSConfig(tlsConfig *tls.Config) DialXOption

func DialX_WithTLSTimeout added in v1.2.6

func DialX_WithTLSTimeout(t time.Duration) DialXOption

func DialX_WithTimeout added in v1.2.6

func DialX_WithTimeout(timeout time.Duration) DialXOption

func DialX_WithTimeoutRetry added in v1.2.6

func DialX_WithTimeoutRetry(max int) DialXOption

func DialX_WithTimeoutRetryWait added in v1.2.6

func DialX_WithTimeoutRetryWait(timeout time.Duration) DialXOption

func DialX_WithTimeoutRetryWaitRange added in v1.2.6

func DialX_WithTimeoutRetryWaitRange(min, max time.Duration) DialXOption

type DoHDNSResponse

type DoHDNSResponse struct {
	Status   int  `json:"Status"`
	TC       bool `json:"TC"`
	RD       bool `json:"RD"`
	RA       bool `json:"RA"`
	AD       bool `json:"AD"`
	CD       bool `json:"CD"`
	Question json.RawMessage
	Answer   []struct {
		Name string `json:"name"`
		Type int    `json:"type"`
		TTL  int    `json:"TTL"`
		Data string `json:"data"`
	} `json:"Answer"`
}

type ReliableDNSConfig

type ReliableDNSConfig struct {
	Timeout time.Duration
	Hosts   map[string]string

	PreferTCP   bool
	FallbackTCP bool
	RetryTimes  int // default 3

	// DoH config
	PreferDoH   bool
	FallbackDoH bool // as backup
	SpecificDoH []string

	// NoCache
	NoCache bool

	// Disable System Resolver
	DisableSystemResolver bool

	// SpecificDNSServers 作为备选项
	FallbackSpecificDNS bool

	SpecificDNSServers []string

	// ctx
	BaseContext context.Context

	Callback func(dnsType string, domain string, ip, fromServer, method string)

	OnFinished func()
	// contains filtered or unexported fields
}

func NewBackupInitilizedReliableDNSConfig

func NewBackupInitilizedReliableDNSConfig() *ReliableDNSConfig

func NewDefaultReliableDNSConfig

func NewDefaultReliableDNSConfig() *ReliableDNSConfig

func (*ReliableDNSConfig) GetBaseContext

func (r *ReliableDNSConfig) GetBaseContext() context.Context

type TLSInspectResult added in v1.2.7

type TLSInspectResult struct {
	Description     string
	Raw             []byte
	RelativeDomains []string
	RelativeEmail   []string
	RelativeAccount []string
	RelativeURIs    []string
}

func TLSInspect added in v1.2.7

func TLSInspect(addr string) ([]*TLSInspectResult, error)

func (TLSInspectResult) Show added in v1.2.7

func (t TLSInspectResult) Show()

func (TLSInspectResult) String added in v1.2.7

func (t TLSInspectResult) String() string

type TLSStrategy added in v1.2.6

type TLSStrategy string
const (
	TLS_Strategy_GMDail                   TLSStrategy = "gmtls"
	TLS_Strategy_GMDial_Without_GMSupport TLSStrategy = "gmtls-ns"
	TLS_Strategy_Ordinary                 TLSStrategy = "tls"
)

Jump to

Keyboard shortcuts

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