dnsutils

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 9 Imported by: 0

README

dnsutils

build Go report codecov Documentation

Documentation

Index

Constants

View Source
const (
	TypeA     = "A"
	TypeAAAA  = "AAAA"
	TypeNS    = "NS"
	TypeMX    = "MX"
	TypeTXT   = "TXT"
	TypeSRV   = "SRV"
	TypeCNAME = "CNAME"
	TypePTR   = "PTR"
)

Variables

View Source
var (
	TypesAll = []string{
		TypeA,
		TypeAAAA,
		TypeNS,
		TypeMX,
		TypeTXT,
		TypeSRV,
		TypeCNAME,
		TypePTR,
	}

	DefaultClient = &dns.Client{
		Timeout: time.Second * 3,
	}
)

Functions

func PTR

func PTR(ip net.IP) string

PTR returns domain name for IP.

func Query

func Query(ip net.IP, name, qtype string) ([]string, error)

Query returns DNS Query result for the given name using given NS.

func Subdomains

func Subdomains(sub, base string) []string

Subdomains returns list of subdomains of base domain. sub: a.b.c.d.com, base: d.com -> c.d.com, b.c.d.com, a.b.c.d.com

Types

type Meta added in v0.2.4

type Meta map[string]interface{}

type Pool added in v0.2.0

type Pool struct {
	// contains filtered or unexported fields
}

Pool represents Pool of DNS servers.

func NewPool added in v0.2.0

func NewPool(ips []net.IP, rate, capacity int) *Pool

NewPool returns new instane of Pool.

func (*Pool) Close added in v0.2.1

func (p *Pool) Close()

Close closes all internal resources.

func (*Pool) Start added in v0.2.0

func (p *Pool) Start()

Start start internal refill goroutine.

func (*Pool) Take added in v0.2.0

func (p *Pool) Take() *Server

Take returns ready DNS Server from Pool.

type Resolver

type Resolver interface {
	TaskGroup

	Start()
	Group() TaskGroup
}

Resolver represents DNS resolve tasks queue.

func NewResolver

func NewResolver(servers []net.IP, workersCount, rateLimit int) Resolver

NewResolver creates new resolver instance using provided servers and options.

type Result

type Result struct {
	// Name is a resolved DNS name.
	Name string

	// Answers is a map from Query type to list of results.
	Answers map[string][]string

	// Meta is a meta data copied from Task.
	Meta map[string]interface{}
}

Result represents DNS resolver task result.

func (*Result) IsEmpty

func (r *Result) IsEmpty() bool

IsEmpty returns true if there are no answers in the result.

func (*Result) ResultType

func (r *Result) ResultType()

ResultType allows Result to implement jobq.Result interface.

func (*Result) SortAnswers

func (r *Result) SortAnswers()

SortAnswers sorts Result answers.

type Server added in v0.2.0

type Server struct {
	// IP address of the Server.
	IP net.IP
	// contains filtered or unexported fields
}

Server represents DNS Server.

func (*Server) Query added in v0.2.0

func (s *Server) Query(name string, qtype string) ([]string, error)

Query makes DNS query and returns its result.

func (*Server) Rate added in v0.2.0

func (s *Server) Rate() float64

Rate returns average queries per second for the Server.

type Task

type Task struct {

	// Name is a DNS name to resolve.
	Name string

	// Qtypes is a list of Query types to use.
	Qtypes []string

	// Meta is metadata which will be copied to result.
	Meta map[string]interface{}
	// contains filtered or unexported fields
}

Task represents DNS resolver task.

func (*Task) TaskType

func (t *Task) TaskType()

TaskType allows Task to implement jobq.Task interface.

type TaskGroup

type TaskGroup interface {
	// Add adds task to group.
	Add(name string, qtypes []string, meta Meta)

	// Next returns next task Result or error.
	Next(*Result, *error) bool

	// Wait blocks until all tasks in group are processed.
	Wait()

	// Close closes all internal resources.
	// Blocks until all internal goroutines are stopped.
	Close()

	// Speed returns processing speed (tasks per second).
	Speed() float64

	// Progress returns progress as number from 0 to 1.
	Progress() float64
}

TaskGroup represents group of DNS resolve to process.

Jump to

Keyboard shortcuts

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