Documentation
¶
Overview ¶
Package provider implements protocols to detect public IP addresses.
Index ¶
- func CloseIdleConnections()
- func Name(p Provider) string
- type Provider
- func MustNewCustomURL(rawURL string) Provider
- func MustNewDebugConst(raw string) Provider
- func NewCloudflareDOH() Provider
- func NewCloudflareTrace() Provider
- func NewCloudflareTraceCustom(url string) Provider
- func NewCustomURL(ppfmt pp.PP, rawURL string) (Provider, bool)
- func NewDebugConst(ppfmt pp.PP, raw string) (Provider, bool)
- func NewIpify() Provider
- func NewLocal() Provider
- func NewLocalWithInterface(iface string) Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseIdleConnections ¶ added in v1.15.0
func CloseIdleConnections()
CloseIdleConnections closes all idle (keep-alive) connections after the detection. This is to prevent some lingering TCP connections from disturbing the IP detection.
Types ¶
type Provider ¶
type Provider interface { Name() string GetIP(ctx context.Context, ppfmt pp.PP, ipNet ipnet.Type) (netip.Addr, bool) }
Provider is the abstraction of a protocol to detect public IP addresses.
func MustNewCustomURL ¶ added in v1.15.0
MustNewCustomURL creates a HTTP provider and panics if it fails.
func MustNewDebugConst ¶ added in v1.15.1
MustNewDebugConst creates a protocol.Const provider and panics if it fails.
func NewCloudflareDOH ¶
func NewCloudflareDOH() Provider
NewCloudflareDOH creates a new provider that queries whoami.cloudflare. via Cloudflare DNS over HTTPS. If use1001 is true, 1.0.0.1 is used instead of 1.1.1.1.
func NewCloudflareTrace ¶
func NewCloudflareTrace() Provider
NewCloudflareTrace creates a specialized CloudflareTrace provider that parses https://1.1.1.1/cdn-cgi/trace. If use1001 is true, 1.0.0.1 is used instead of 1.1.1.1.
func NewCloudflareTraceCustom ¶ added in v1.15.1
NewCloudflareTraceCustom creates a specialized CloudflareTrace provider with a specific URL.
func NewCustomURL ¶ added in v1.15.0
NewCustomURL creates a HTTP provider.
func NewDebugConst ¶ added in v1.15.1
NewDebugConst creates a protocol.Const provider.
func NewIpify ¶
func NewIpify() Provider
NewIpify creates a specialized HTTP provider that uses the ipify service.
func NewLocal ¶
func NewLocal() Provider
NewLocal creates a specialized Local provider that uses Cloudflare as the remote server. (No actual UDP packets will be sent to Cloudflare.)
func NewLocalWithInterface ¶ added in v1.15.0
NewLocalWithInterface creates a protocol.LocalWithInterface provider.