dns_helper

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package dns_helper contains helpers to interact with the Domain Name System.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DNSFindNameservers deprecated

func DNSFindNameservers(t testing.TestingT, fqdn string, resolvers []string) []string

DNSFindNameservers tries to find the NS record for the given FQDN, iterating down the domain hierarchy until it finds the NS records and returns them. Fails if there's any error or no NS record is found up to the apex domain.

Deprecated: Use DNSFindNameserversContext instead.

func DNSFindNameserversContext added in v1.0.0

func DNSFindNameserversContext(t testing.TestingT, ctx context.Context, fqdn string, resolvers []string) []string

DNSFindNameserversContext tries to find the NS record for the given FQDN, iterating down the domain hierarchy until it finds the NS records and returns them. Fails if there's any error or no NS record is found up to the apex domain.

func DNSFindNameserversContextE added in v1.0.0

func DNSFindNameserversContextE(t testing.TestingT, ctx context.Context, fqdn string, resolvers []string) ([]string, error)

DNSFindNameserversContextE tries to find the NS record for the given FQDN, iterating down the domain hierarchy until it finds the NS records and returns them. Returns NSNotFoundError if the apex domain is reached with no result.

func DNSFindNameserversE deprecated

func DNSFindNameserversE(t testing.TestingT, fqdn string, resolvers []string) ([]string, error)

DNSFindNameserversE tries to find the NS record for the given FQDN, iterating down the domain hierarchy until it finds the NS records and returns them. Returns NSNotFoundError if the apex domain is reached with no result.

Deprecated: Use DNSFindNameserversContextE instead.

func DNSLookupAuthoritativeAllWithRetry deprecated

func DNSLookupAuthoritativeAllWithRetry(t testing.TestingT, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration)

DNSLookupAuthoritativeAllWithRetry repeatedly sends DNS requests for the specified record and type, until ALL authoritative nameservers reply with the exact same non-empty answers or until max retries has been exceeded. If defined, uses the given resolvers instead of the default system ones to find the authoritative nameservers. Fails when max retries has been exceeded.

Deprecated: Use DNSLookupAuthoritativeAllWithRetryContext instead.

func DNSLookupAuthoritativeAllWithRetryContext added in v1.0.0

func DNSLookupAuthoritativeAllWithRetryContext(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration)

DNSLookupAuthoritativeAllWithRetryContext repeatedly sends DNS requests for the specified record and type, until ALL authoritative nameservers reply with the exact same non-empty answers or until max retries has been exceeded. If defined, uses the given resolvers instead of the default system ones to find the authoritative nameservers. Fails when max retries has been exceeded.

func DNSLookupAuthoritativeAllWithValidation deprecated

func DNSLookupAuthoritativeAllWithValidation(t testing.TestingT, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers)

DNSLookupAuthoritativeAllWithValidation gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers and match the expectedAnswers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any underlying error from DNSLookupAuthoritativeAllWithValidationContextE.

Deprecated: Use DNSLookupAuthoritativeAllWithValidationContext instead.

func DNSLookupAuthoritativeAllWithValidationContext added in v1.0.0

func DNSLookupAuthoritativeAllWithValidationContext(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers)

DNSLookupAuthoritativeAllWithValidationContext gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers and match the expectedAnswers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any underlying error from DNSLookupAuthoritativeAllWithValidationContextE.

func DNSLookupAuthoritativeAllWithValidationContextE added in v1.0.0

func DNSLookupAuthoritativeAllWithValidationContextE(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers) error

DNSLookupAuthoritativeAllWithValidationContextE gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers and match the expectedAnswers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns ValidationError when expectedAnswers differ from the obtained ones. Returns any underlying error from DNSLookupAuthoritativeAllContextE.

func DNSLookupAuthoritativeAllWithValidationE deprecated

func DNSLookupAuthoritativeAllWithValidationE(t testing.TestingT, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers) error

DNSLookupAuthoritativeAllWithValidationE gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers and match the expectedAnswers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns ValidationError when expectedAnswers differ from the obtained ones. Returns any underlying error from DNSLookupAuthoritativeAllContextE.

Deprecated: Use DNSLookupAuthoritativeAllWithValidationContextE instead.

func DNSLookupAuthoritativeAllWithValidationRetry deprecated

func DNSLookupAuthoritativeAllWithValidationRetry(t testing.TestingT, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers, maxRetries int, sleepBetweenRetries time.Duration)

DNSLookupAuthoritativeAllWithValidationRetry repeatedly gets authoritative answers for the specified record and type until ALL the authoritative nameservers found give the same answers and match the expectedAnswers, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails when max retries has been exceeded.

Deprecated: Use DNSLookupAuthoritativeAllWithValidationRetryContext instead.

func DNSLookupAuthoritativeAllWithValidationRetryContext added in v1.0.0

func DNSLookupAuthoritativeAllWithValidationRetryContext(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers, maxRetries int, sleepBetweenRetries time.Duration)

DNSLookupAuthoritativeAllWithValidationRetryContext repeatedly gets authoritative answers for the specified record and type until ALL the authoritative nameservers found give the same answers and match the expectedAnswers, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails when max retries has been exceeded.

func DNSLookupAuthoritativeAllWithValidationRetryContextE added in v1.0.0

func DNSLookupAuthoritativeAllWithValidationRetryContextE(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers, maxRetries int, sleepBetweenRetries time.Duration) error

DNSLookupAuthoritativeAllWithValidationRetryContextE repeatedly gets authoritative answers for the specified record and type until ALL the authoritative nameservers found give the same answers and match the expectedAnswers, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers.

func DNSLookupAuthoritativeAllWithValidationRetryE deprecated

func DNSLookupAuthoritativeAllWithValidationRetryE(t testing.TestingT, query DNSQuery, resolvers []string, expectedAnswers DNSAnswers, maxRetries int, sleepBetweenRetries time.Duration) error

DNSLookupAuthoritativeAllWithValidationRetryE repeatedly gets authoritative answers for the specified record and type until ALL the authoritative nameservers found give the same answers and match the expectedAnswers, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers.

Deprecated: Use DNSLookupAuthoritativeAllWithValidationRetryContextE instead.

Types

type DNSAnswer

type DNSAnswer struct {
	Type, Value string
}

DNSAnswer represents a single DNS answer with a record type and value.

func (DNSAnswer) String

func (a DNSAnswer) String() string

String returns a human-readable representation of the DNS answer.

type DNSAnswers

type DNSAnswers []DNSAnswer

DNSAnswers is a collection of DNS answers.

func DNSLookup deprecated

func DNSLookup(t testing.TestingT, query DNSQuery, resolvers []string) DNSAnswers

DNSLookup sends a DNS query for the specified record and type using the given resolvers. Fails on any error. Supported record types: A, AAAA, CNAME, MX, NS, TXT

Deprecated: Use DNSLookupContext instead.

func DNSLookupAuthoritative deprecated

func DNSLookupAuthoritative(t testing.TestingT, query DNSQuery, resolvers []string) DNSAnswers

DNSLookupAuthoritative gets authoritative answers for the specified record and type. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeContextE.

Deprecated: Use DNSLookupAuthoritativeContext instead.

func DNSLookupAuthoritativeAll deprecated

func DNSLookupAuthoritativeAll(t testing.TestingT, query DNSQuery, resolvers []string) DNSAnswers

DNSLookupAuthoritativeAll gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeAllContextE.

Deprecated: Use DNSLookupAuthoritativeAllContext instead.

func DNSLookupAuthoritativeAllContext added in v1.0.0

func DNSLookupAuthoritativeAllContext(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string) DNSAnswers

DNSLookupAuthoritativeAllContext gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeAllContextE.

func DNSLookupAuthoritativeAllContextE added in v1.0.0

func DNSLookupAuthoritativeAllContextE(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupAuthoritativeAllContextE gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns InconsistentAuthoritativeError when any authoritative nameserver gives a different answer. Returns any underlying error.

func DNSLookupAuthoritativeAllE deprecated

func DNSLookupAuthoritativeAllE(t testing.TestingT, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupAuthoritativeAllE gets authoritative answers for the specified record and type. All the authoritative nameservers found must give the same answers. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns InconsistentAuthoritativeError when any authoritative nameserver gives a different answer. Returns any underlying error.

Deprecated: Use DNSLookupAuthoritativeAllContextE instead.

func DNSLookupAuthoritativeAllWithRetryContextE added in v1.0.0

func DNSLookupAuthoritativeAllWithRetryContextE(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) (DNSAnswers, error)

DNSLookupAuthoritativeAllWithRetryContextE repeatedly sends DNS requests for the specified record and type, until ALL authoritative nameservers reply with the exact same non-empty answers or until max retries has been exceeded. If defined, uses the given resolvers instead of the default system ones to find the authoritative nameservers.

func DNSLookupAuthoritativeAllWithRetryE deprecated

func DNSLookupAuthoritativeAllWithRetryE(t testing.TestingT, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) (DNSAnswers, error)

DNSLookupAuthoritativeAllWithRetryE repeatedly sends DNS requests for the specified record and type, until ALL authoritative nameservers reply with the exact same non-empty answers or until max retries has been exceeded. If defined, uses the given resolvers instead of the default system ones to find the authoritative nameservers.

Deprecated: Use DNSLookupAuthoritativeAllWithRetryContextE instead.

func DNSLookupAuthoritativeContext added in v1.0.0

func DNSLookupAuthoritativeContext(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string) DNSAnswers

DNSLookupAuthoritativeContext gets authoritative answers for the specified record and type. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeContextE.

func DNSLookupAuthoritativeContextE added in v1.0.0

func DNSLookupAuthoritativeContextE(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupAuthoritativeContextE gets authoritative answers for the specified record and type. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns NotFoundError when no answer found in any authoritative nameserver. Returns any underlying error from individual lookups.

func DNSLookupAuthoritativeE deprecated

func DNSLookupAuthoritativeE(t testing.TestingT, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupAuthoritativeE gets authoritative answers for the specified record and type. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Returns NotFoundError when no answer found in any authoritative nameserver. Returns any underlying error from individual lookups.

Deprecated: Use DNSLookupAuthoritativeContextE instead.

func DNSLookupAuthoritativeWithRetry deprecated

func DNSLookupAuthoritativeWithRetry(t testing.TestingT, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) DNSAnswers

DNSLookupAuthoritativeWithRetry repeatedly gets authoritative answers for the specified record and type until ANY of the authoritative nameservers found replies with a non-empty answer, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeWithRetryContextE.

Deprecated: Use DNSLookupAuthoritativeWithRetryContext instead.

func DNSLookupAuthoritativeWithRetryContext added in v1.0.0

func DNSLookupAuthoritativeWithRetryContext(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) DNSAnswers

DNSLookupAuthoritativeWithRetryContext repeatedly gets authoritative answers for the specified record and type until ANY of the authoritative nameservers found replies with a non-empty answer, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers. Fails on any error from DNSLookupAuthoritativeWithRetryContextE.

func DNSLookupAuthoritativeWithRetryContextE added in v1.0.0

func DNSLookupAuthoritativeWithRetryContextE(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) (DNSAnswers, error)

DNSLookupAuthoritativeWithRetryContextE repeatedly gets authoritative answers for the specified record and type until ANY of the authoritative nameservers found replies with a non-empty answer, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers.

func DNSLookupAuthoritativeWithRetryE deprecated

func DNSLookupAuthoritativeWithRetryE(t testing.TestingT, query DNSQuery, resolvers []string, maxRetries int, sleepBetweenRetries time.Duration) (DNSAnswers, error)

DNSLookupAuthoritativeWithRetryE repeatedly gets authoritative answers for the specified record and type until ANY of the authoritative nameservers found replies with a non-empty answer, or until max retries has been exceeded. If resolvers are defined, uses them instead of the default system ones to find the authoritative nameservers.

Deprecated: Use DNSLookupAuthoritativeWithRetryContextE instead.

func DNSLookupContext added in v1.0.0

func DNSLookupContext(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string) DNSAnswers

DNSLookupContext sends a DNS query for the specified record and type using the given resolvers. Fails on any error. Supported record types: A, AAAA, CNAME, MX, NS, TXT

func DNSLookupContextE added in v1.0.0

func DNSLookupContextE(t testing.TestingT, ctx context.Context, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupContextE sends a DNS query for the specified record and type using the given resolvers. Returns QueryTypeError when record type is not supported. Returns NoResolversError when no resolvers are provided. Returns any underlying error. Supported record types: A, AAAA, CNAME, MX, NS, TXT

func DNSLookupE deprecated

func DNSLookupE(t testing.TestingT, query DNSQuery, resolvers []string) (DNSAnswers, error)

DNSLookupE sends a DNS query for the specified record and type using the given resolvers. Returns QueryTypeError when record type is not supported. Returns NoResolversError when no resolvers are provided. Returns any underlying error. Supported record types: A, AAAA, CNAME, MX, NS, TXT

Deprecated: Use DNSLookupContextE instead.

func (DNSAnswers) Sort

func (a DNSAnswers) Sort()

Sort sorts the answers by type and value.

type DNSQuery

type DNSQuery struct {
	Type, Name string
}

DNSQuery represents a DNS query with a record type and name.

type InconsistentAuthoritativeError

type InconsistentAuthoritativeError struct {
	Query           DNSQuery
	Answers         DNSAnswers
	Nameserver      string
	PreviousAnswers DNSAnswers
}

InconsistentAuthoritativeError is an error that occurs if an authoritative answer is different from another

func (*InconsistentAuthoritativeError) Error

type MaxRetriesExceeded

type MaxRetriesExceeded struct {
	Description string
	MaxRetries  int
}

MaxRetriesExceeded is an error that occurs when the maximum amount of retries is exceeded.

func (MaxRetriesExceeded) Error

func (err MaxRetriesExceeded) Error() string

type NSNotFoundError

type NSNotFoundError struct {
	FQDN       string
	Nameserver string
}

NSNotFoundError is an error that occurs if no NS records found

func (NSNotFoundError) Error

func (err NSNotFoundError) Error() string

type NoResolversError

type NoResolversError struct{}

NoResolversError is an error that occurs if no resolvers have been set for DNSLookupE

func (NoResolversError) Error

func (err NoResolversError) Error() string

type NotFoundError

type NotFoundError struct {
	Query      DNSQuery
	Nameserver string
}

NotFoundError is an error that occurs if no answer found

func (NotFoundError) Error

func (err NotFoundError) Error() string

type QueryTypeError

type QueryTypeError struct {
	Type string
}

QueryTypeError is an error that occurs if the DNS query type is not supported

func (QueryTypeError) Error

func (err QueryTypeError) Error() string

type ValidationError

type ValidationError struct {
	Query           DNSQuery
	Answers         DNSAnswers
	ExpectedAnswers DNSAnswers
}

ValidationError is an error that occurs when answers validation fails

func (*ValidationError) Error

func (err *ValidationError) Error() string

Jump to

Keyboard shortcuts

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