Documentation
¶
Index ¶
- Constants
- Variables
- func AddHost(host string, ip string)
- func DeleteHost(host string)
- func DialContext(ctx context.Context, target string, proxies ...string) (net.Conn, error)
- func DialContextWithoutProxy(ctx context.Context, addr string) (net.Conn, error)
- func DialTCPTimeout(timeout time.Duration, target string, proxies ...string) (net.Conn, error)
- func DialTCPTimeoutForceProxy(timeout time.Duration, target string, proxy string) (net.Conn, error)
- func DialTLSTimeout(timeout time.Duration, target string, tlsConfig any, proxy ...string) (net.Conn, error)
- func DialTimeout(connectTimeout time.Duration, target string, proxy ...string) (net.Conn, error)
- func DialTimeoutWithoutProxy(timeout time.Duration, network, addr string) (net.Conn, error)
- func DialUdpX(target string, opt ...DialXOption) (*net.UDPConn, *net.UDPAddr, error)
- func DialX(target string, opt ...DialXOption) (net.Conn, error)
- func FixProxy(i string) string
- func GetDefaultHostsFilePath() string
- func GetDialxCPS() int64
- func GetHost(host string) (ip string, ok bool)
- func GetProxyFromEnv() string
- func IsExistedHost(host string) bool
- func IsTLSService(addr string, proxies ...string) bool
- func IsTLSServiceContext(ctx context.Context, addr string, proxies ...string) bool
- func IsUTLSCertCAMatch(chain utls.Certificate, certReq *utls.CertificateRequestInfo) bool
- func LoadCertificatesConfig(i any) error
- func LoadHostsFromFile(p string) error
- func LoadP12Bytes(p12bytes []byte, password string, hostPattern string) error
- func LookupAll(host string, opt ...DNSOption) []string
- func LookupCallback(host string, h func(dnsType, domain, ip, fromServer string, method string), ...) error
- func LookupFirst(host string, opt ...DNSOption) string
- func NewDefaultHTTPClient(proxy ...string) *http.Client
- func NewDialContextFunc(timeout time.Duration, opts ...DNSOption) func(ctx context.Context, network string, addr string) (net.Conn, error)
- func NewDialGMTLSContextFunc(enableGM bool, preferGMTLS bool, onlyGMTLS bool, timeout time.Duration, ...) func(ctx context.Context, network string, addr string) (net.Conn, error)
- func ProxyCheck(proxy string, connectTimeout time.Duration) (net.Conn, error)
- func ResetPresetCertificates()
- func SetDefaultDNSOptions(opt ...DNSOption)
- func SetDefaultDialXConfig(opt ...DialXOption)
- func SetSystemProxy(s SystemProxySetting) error
- func UnsetProxyFromEnv()
- func UpgradeToTLSConnection(conn net.Conn, sni string, i any, spec *utls.ClientHelloSpec) (net.Conn, error)
- func UpgradeToTLSConnectionWithTimeout(conn net.Conn, sni string, i any, timeout time.Duration, ...) (net.Conn, error)
- type DNSOption
- func GetDefaultOptions() []DNSOption
- func WithDNSCallback(cb func(dnsType, domain, ip, fromServer, method string)) DNSOption
- func WithDNSContext(ctx context.Context) DNSOption
- func WithDNSDisableSystemResolver(b bool) DNSOption
- func WithDNSDisabledDomain(domain ...string) DNSOption
- func WithDNSFallbackDoH(b bool) DNSOption
- func WithDNSFallbackSpecificDNS(b bool) DNSOption
- func WithDNSFallbackTCP(b bool) DNSOption
- func WithDNSNoCache(b bool) DNSOption
- func WithDNSOnFinished(cb func()) DNSOption
- func WithDNSPreferDoH(b bool) DNSOption
- func WithDNSPreferTCP(b bool) DNSOption
- func WithDNSRetryTimes(i int) DNSOption
- func WithDNSServers(s ...string) DNSOption
- func WithDNSSpecificDoH(s ...string) DNSOption
- func WithTemporaryHosts(i map[string]string) DNSOption
- func WithTimeout(timeout time.Duration) DNSOption
- type DialXOption
- func DialX_Debug(b bool) DialXOption
- func DialX_WithClientHelloSpec(spec *utls.ClientHelloSpec) DialXOption
- func DialX_WithDNSOptions(opt ...DNSOption) DialXOption
- func DialX_WithDialTraceInfo(traceInfo *DialXTraceInfo) DialXOption
- func DialX_WithDialer(dialer func(duration time.Duration, target string) (net.Conn, error)) DialXOption
- func DialX_WithDisableProxy(b bool) DialXOption
- func DialX_WithDisallowAddress(a ...string) DialXOption
- func DialX_WithEnableSystemProxyFromEnv(b bool) DialXOption
- func DialX_WithForceProxy(b bool) DialXOption
- func DialX_WithGMTLSConfig(config *gmtls.Config) DialXOption
- func DialX_WithGMTLSOnly(b bool) DialXOption
- func DialX_WithGMTLSPrefer(b bool) DialXOption
- func DialX_WithGMTLSSupport(b bool) DialXOption
- func DialX_WithKeepAlive(aliveTime time.Duration) DialXOption
- func DialX_WithLocalAddr(addr *net.UDPAddr) DialXOption
- func DialX_WithProxy(proxy ...string) DialXOption
- func DialX_WithSNI(sni string) DialXOption
- func DialX_WithStrongHostMode(localIP string) DialXOption
- func DialX_WithTCPLocalAddr(addr *net.TCPAddr) DialXOption
- func DialX_WithTLS(b bool) DialXOption
- func DialX_WithTLSConfig(tlsConfig any) DialXOption
- func DialX_WithTLSNextProto(nextProtos ...string) DialXOption
- func DialX_WithTLSTimeout(t time.Duration) DialXOption
- func DialX_WithTimeout(timeout time.Duration) DialXOption
- func DialX_WithTimeoutRetry(max int) DialXOption
- func DialX_WithTimeoutRetryWait(timeout time.Duration) DialXOption
- func DialX_WithTimeoutRetryWaitRange(min, max time.Duration) DialXOption
- func DialX_WithUdpJustListen(b bool) DialXOption
- type DialXTraceInfo
- type DoHDNSResponse
- type HandshakeConn
- type HostCertMapping
- type ProxyCredential
- type ReliableDNSConfig
- type SystemProxySetting
- type TLSInspectResult
- func TLSInspect(addr string) ([]*TLSInspectResult, error)
- func TLSInspectContext(ctx context.Context, addr string, proto ...string) ([]*TLSInspectResult, error)
- func TLSInspectForceHttp1_1(addr string) ([]*TLSInspectResult, error)
- func TLSInspectForceHttp2(addr string) ([]*TLSInspectResult, error)
- func TLSInspectTimeout(addr string, seconds float64, proto ...string) ([]*TLSInspectResult, error)
- type TLSStrategy
Constants ¶
const ( SOCKS4 = iota SOCKS4A SOCKS5 )
Constants to choose which version of SOCKS protocol to use.
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 ¶
var DefaultCustomDNSServers = []string{
"223.5.5.5", "223.6.6.6",
"120.53.53.53", "1.1.1.1",
"8.8.8.8",
}
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",
}
var ErrNotImpl = errors.New(fmt.Sprintf("systemproxy not implemented on this platform: %v", runtime.GOOS))
ErrNotImpl error is returned when the current platform isn't supported yet.
var ErrorProxyAuthFailed = utils.Error("invalid proxy username or password")
Functions ¶
func DeleteHost ¶
func DeleteHost(host string)
func DialContext ¶ added in v1.2.5
func DialContextWithoutProxy ¶
DialContextWithoutProxy dials a connection with a context.
func DialTCPTimeout ¶
DialTCPTimeout is alias for DialTimeout
func DialTLSTimeout ¶
func DialTLSTimeout(timeout time.Duration, target string, tlsConfig any, proxy ...string) (net.Conn, error)
DialTLSTimeout is a shortcut for DialX with timeout
func DialTimeout ¶
DialTimeout is a shortcut for DialX with timeout
func DialTimeoutWithoutProxy ¶
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 GetDefaultHostsFilePath ¶
func GetDefaultHostsFilePath() string
func GetDialxCPS ¶
func GetDialxCPS() int64
func GetProxyFromEnv ¶
func GetProxyFromEnv() string
func IsExistedHost ¶
func IsTLSService ¶
func IsTLSServiceContext ¶
func IsUTLSCertCAMatch ¶
func IsUTLSCertCAMatch(chain utls.Certificate, certReq *utls.CertificateRequestInfo) bool
func LoadCertificatesConfig ¶ added in v1.2.7
func LoadP12Bytes ¶ added in v1.2.7
func LookupCallback ¶
func LookupFirst ¶
func NewDefaultHTTPClient ¶ added in v1.2.6
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 ProxyCheck ¶ added in v1.2.9
func ResetPresetCertificates ¶
func ResetPresetCertificates()
func SetDefaultDNSOptions ¶ added in v1.2.8
func SetDefaultDNSOptions(opt ...DNSOption)
func SetDefaultDialXConfig ¶ added in v1.2.8
func SetDefaultDialXConfig(opt ...DialXOption)
func SetSystemProxy ¶
func SetSystemProxy(s SystemProxySetting) error
Set updates systemwide proxy settings.
func UnsetProxyFromEnv ¶ added in v1.2.8
func UnsetProxyFromEnv()
func UpgradeToTLSConnection ¶
Types ¶
type DNSOption ¶
type DNSOption func(*ReliableDNSConfig)
func GetDefaultOptions ¶
func GetDefaultOptions() []DNSOption
func WithDNSCallback ¶
func WithDNSContext ¶
func WithDNSDisabledDomain ¶ added in v1.2.8
func WithDNSFallbackDoH ¶
func WithDNSFallbackTCP ¶
func WithDNSNoCache ¶
func WithDNSOnFinished ¶ added in v1.2.6
func WithDNSOnFinished(cb func()) DNSOption
func WithDNSPreferDoH ¶
func WithDNSPreferTCP ¶
func WithDNSRetryTimes ¶
func WithDNSServers ¶
func WithDNSSpecificDoH ¶
func WithTemporaryHosts ¶
func WithTimeout ¶
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_WithClientHelloSpec ¶
func DialX_WithClientHelloSpec(spec *utls.ClientHelloSpec) DialXOption
func DialX_WithDNSOptions ¶ added in v1.2.6
func DialX_WithDNSOptions(opt ...DNSOption) DialXOption
func DialX_WithDialTraceInfo ¶
func DialX_WithDialTraceInfo(traceInfo *DialXTraceInfo) DialXOption
func DialX_WithDialer ¶
func DialX_WithDisableProxy ¶ added in v1.2.8
func DialX_WithDisableProxy(b bool) DialXOption
func DialX_WithDisallowAddress ¶ added in v1.2.8
func DialX_WithDisallowAddress(a ...string) DialXOption
func DialX_WithEnableSystemProxyFromEnv ¶ added in v1.2.8
func DialX_WithEnableSystemProxyFromEnv(b bool) DialXOption
func DialX_WithForceProxy ¶ added in v1.2.8
func DialX_WithForceProxy(b bool) 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_WithKeepAlive ¶ added in v1.2.7
func DialX_WithKeepAlive(aliveTime time.Duration) DialXOption
func DialX_WithLocalAddr ¶
func DialX_WithLocalAddr(addr *net.UDPAddr) 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_WithStrongHostMode ¶
func DialX_WithStrongHostMode(localIP string) DialXOption
DialX_WithStrongHostMode enables strong host mode for dialing In strong host mode, the connection will be bound to a specific local IP address This is important for transparent proxy scenarios where the connection must be bound to a specific network interface
func DialX_WithTCPLocalAddr ¶
func DialX_WithTCPLocalAddr(addr *net.TCPAddr) DialXOption
DialX_WithTCPLocalAddr sets the local TCP address for binding to a specific network interface
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 any) DialXOption
func DialX_WithTLSNextProto ¶ added in v1.2.8
func DialX_WithTLSNextProto(nextProtos ...string) 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
func DialX_WithUdpJustListen ¶
func DialX_WithUdpJustListen(b bool) DialXOption
type DialXTraceInfo ¶
type DialXTraceInfo struct {
// dial 耗时 (包括重试
TotalTime time.Duration
// tcp dial time
TCPtime time.Duration
// tls 握手耗时
TLSHandshakeTime time.Duration
}
func NewDialXTraceInfo ¶
func NewDialXTraceInfo() *DialXTraceInfo
func (*DialXTraceInfo) SetTCPDuration ¶
func (d *DialXTraceInfo) SetTCPDuration(t time.Duration)
func (*DialXTraceInfo) SetTLSHandshakeDuration ¶
func (d *DialXTraceInfo) SetTLSHandshakeDuration(t time.Duration)
func (*DialXTraceInfo) SetTotalDuration ¶
func (d *DialXTraceInfo) SetTotalDuration(t time.Duration)
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 HandshakeConn ¶
type HostCertMapping ¶
type HostCertMapping struct {
HostPattern string // 支持glob: *.example.com, api-*.com
Certificate gmtls.Certificate
UCertificate utls.Certificate
}
type ProxyCredential ¶
type ProxyCredential struct {
// contains filtered or unexported fields
}
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()
// blacklist
DisabledDomain *utils.GlobFilter
// 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 SystemProxySetting ¶
type SystemProxySetting struct {
// Enabled is true if static (i.e. non-PAC) proxy is enabled
Enabled bool
// DefaultServer is the server used for all protocols.
DefaultServer string
}
SystemProxySetting represents systemwide proxy settings.
func GetSystemProxy ¶
func GetSystemProxy() (SystemProxySetting, error)
Get returns the current systemwide proxy settings.
type TLSInspectResult ¶ added in v1.2.7
type TLSInspectResult struct {
Version uint16
CipherSuite uint16
ServerName string
Protocol string
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)
Inspect 检查目标地址的TLS证书,并返回其证书信息与错误 Example: ``` cert, err := tls.Inspect("yaklang.io:443") ```
func TLSInspectContext ¶
func TLSInspectForceHttp1_1 ¶ added in v1.3.2
func TLSInspectForceHttp1_1(addr string) ([]*TLSInspectResult, error)
InspectForceHttp1_1 检查目标地址的TLS证书,并返回其证书信息与错误,强制使用HTTP/1.1协议 Example: ``` cert, err := tls.InspectForceHttp1_1("yaklang.io:443") ```
func TLSInspectForceHttp2 ¶ added in v1.3.2
func TLSInspectForceHttp2(addr string) ([]*TLSInspectResult, error)
InspectForceHttp2 检查目标地址的TLS证书,并返回其证书信息与错误,强制使用HTTP/2协议 Example: ``` cert, err := tls.InspectForceHttp2("yaklang.io:443") ```
func TLSInspectTimeout ¶ added in v1.3.1
func TLSInspectTimeout(addr string, seconds float64, proto ...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" )