dns

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dns implements DNS-provider-based mirror testing: resolve a mirror's hostname through different resolvers (UDP, DoH, DoT, or the system) and probe connectivity to the mirror via each provider's IPs. Diverging answers can reveal poisoning, filtering or broken geo-DNS.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CloudflareUDP is 1.1.1.1 over UDP.
	CloudflareUDP = UDP{Addr: "1.1.1.1"}
	// CloudflareDoH is the 1.1.1.1 DNS-over-HTTPS endpoint.
	CloudflareDoH = DoH{URL: "https://cloudflare-dns.com/dns-query"}
	// CloudflareDoT is 1.1.1.1 over TLS port 853.
	CloudflareDoT = DoT{Addr: "1.1.1.1"}
	// GoogleUDP is 8.8.8.8 over UDP.
	GoogleUDP = UDP{Addr: "8.8.8.8"}
	// GoogleDoH is the dns.google DNS-over-HTTPS endpoint.
	GoogleDoH = DoH{URL: "https://dns.google/dns-query"}
	// Quad9UDP is 9.9.9.9 over UDP.
	Quad9UDP = UDP{Addr: "9.9.9.9"}
	// Quad9DoH is the quad9 DoH endpoint.
	Quad9DoH = DoH{URL: "https://dns.quad9.net/dns-query"}
	// OpenDNSUDP is 208.67.222.222 over UDP.
	OpenDNSUDP = UDP{Addr: "208.67.222.222"}
	// AdGuardUDP is 94.140.14.14 over UDP.
	AdGuardUDP = UDP{Addr: "94.140.14.14"}
	// AdGuardDoH is the AdGuard DoH endpoint.
	AdGuardDoH = DoH{URL: "https://dns.adguard-dns.com/dns-query"}

	// DefaultProviders is the preset set used when none are specified.
	DefaultProviders = []Provider{
		System{},
		CloudflareUDP,
		GoogleUDP,
		Quad9UDP,
	}
)

Well-known public resolvers. Each entry lists its plain-UDP and encrypted endpoints; pick per Provider as needed.

Functions

This section is empty.

Types

type DoH

type DoH struct {
	// URL is the DoH endpoint accepting GET ?dns=<base64url wireformat>.
	URL string
	// HTTPClient for the DoH requests; default httpx.ClientOr.
	HTTPClient *http.Client
}

DoH resolves via DNS-over-HTTPS (RFC 8484), e.g. https://cloudflare-dns.com/dns-query.

func (DoH) Name

func (d DoH) Name() string

Name implements Provider.

func (DoH) RTT

func (d DoH) RTT(ctx context.Context, host string) (time.Duration, error)

RTT implements Provider.

func (DoH) Resolve

func (d DoH) Resolve(ctx context.Context, host string) ([]net.IP, error)

Resolve implements Provider.

type DoT

type DoT struct {
	Addr string // host:port, default port 853
}

DoT resolves via DNS-over-TLS (port 853).

func (DoT) Name

func (d DoT) Name() string

Name implements Provider.

func (DoT) RTT

func (d DoT) RTT(ctx context.Context, host string) (time.Duration, error)

RTT implements Provider.

func (DoT) Resolve

func (d DoT) Resolve(ctx context.Context, host string) ([]net.IP, error)

Resolve implements Provider.

type Duration

type Duration time.Duration

Duration marshals as a Go duration string.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (Duration) String

func (d Duration) String() string

type ProbeResult

type ProbeResult struct {
	Host      string           `json:"host"`
	Port      string           `json:"port"`
	Providers []ProviderResult `json:"providers"`
	// Divergence describes providers whose IP sets differ from the
	// majority — a poisoning / geo-DNS / filtering signal.
	Divergence string `json:"divergence,omitempty"`
}

ProbeResult aggregates all providers for one mirror host.

func Probe

func Probe(ctx context.Context, host string, providers []Provider, port string) (*ProbeResult, error)

Probe resolves host via each provider and then dials mirrorPort through each provider's resolved IPs (Host header semantics are left to callers; this measures TCP reachability only).

type Provider

type Provider interface {
	// Name identifies the provider in results ("system", "cloudflare", ...).
	Name() string
	// Resolve returns the A/AAAA addresses for host.
	Resolve(ctx context.Context, host string) ([]net.IP, error)
	// RTT measures a resolution round-trip (typically via Resolve timing).
	RTT(ctx context.Context, host string) (time.Duration, error)
}

Provider resolves names through one specific DNS resolver.

type ProviderResult

type ProviderResult struct {
	Provider   string   `json:"provider"`
	IPs        []string `json:"ips"`
	ResolveRTT Duration `json:"resolve_rtt"`
	ConnectRTT Duration `json:"connect_rtt,omitempty"`
	Reachable  bool     `json:"reachable"`
	Error      string   `json:"error,omitempty"`
	IPTag      string   `json:"ip_tag,omitempty"` // diverge / ok
}

ProviderResult reports one provider's view of a mirror host.

type System

type System struct{}

System resolves via the OS resolver (net.Resolver default).

func (System) Name

func (System) Name() string

Name implements Provider.

func (System) RTT

func (System) RTT(ctx context.Context, host string) (time.Duration, error)

RTT implements Provider.

func (System) Resolve

func (System) Resolve(ctx context.Context, host string) ([]net.IP, error)

Resolve implements Provider.

type TLSDialer

type TLSDialer struct{ Addr string }

type UDP

type UDP struct {
	Addr string // host:port; port 53 appended if missing
}

UDP resolves via a classic UDP DNS server (e.g. "1.1.1.1:53").

func (UDP) Name

func (u UDP) Name() string

Name implements Provider.

func (UDP) RTT

func (u UDP) RTT(ctx context.Context, host string) (time.Duration, error)

RTT implements Provider.

func (UDP) Resolve

func (u UDP) Resolve(ctx context.Context, host string) ([]net.IP, error)

Resolve implements Provider.

Jump to

Keyboard shortcuts

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