resolver

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: BSD-3-Clause Imports: 4 Imported by: 7 modules, 7 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.

README

go-dns-resolver

DNS resolver in Golang, based on miekg/dns.

Goal
  1. Simple interface
  2. Rich and neat output
  3. Easy to figure
  4. High performance
Install
go get github.com/Focinfi/go-dns-resolver
Example
package main

import (
  dns "github.com/Focinfi/go-dns-resolver"
  "log"
)

func main() {
  domains := []string{"google.com", "twitter.com"}
  types := []dns.QueryType{dns.TypeA, dns.TypeNS, dns.TypeMX, dns.TypeTXT}

  // Set timeout and retry times
  dns.Config.SetTimeout(uint(2))
  dns.Config.RetryTimes = uint(4)

  // Simple usage
  if results, err := dns.Exchange("google.com", "119.29.29.29", dns.TypeA); err == nil {
    for _, r := range results {
      log.Println(r.Record, r.Type, r.Ttl, r.Priority, r.Content)
    }
  } else {
    log.Fatal(err)
  }

  // Create and setup resolver with domains and types
  resolver := dns.NewResolver("119.29.29.29")
  resolver.Targets(domains...).Types(types...)
  // Lookup
  res := resolver.Lookup()

  //res.ResMap is a map[string]*ResultItem, key is the domain
  for target := range res.ResMap {
    log.Printf("%v: \n", target)
    for _, r := range res.ResMap[target] {
      log.Println(r.Record, r.Type, r.Ttl, r.Priority, r.Content)
    }
  }
}

Output:

google.com A 2m31s 0 216.58.197.110

twitter.com: 
twitter.com A 10m3s 0 78.16.49.15
twitter.com NS 11h49m58s 0 ns1.p34.dynect.net.
twitter.com NS 11h49m58s 0 ns4.p34.dynect.net.
twitter.com NS 11h49m58s 0 ns3.p34.dynect.net.
twitter.com NS 11h49m58s 0 ns2.p34.dynect.net.
google.com: 
google.com TXT 19m26s 0 v=spf1 include:_spf.google.com ~all
google.com A 2m31s 0 216.58.197.110
google.com NS 7h40m6s 0 ns1.google.com.
google.com NS 7h40m6s 0 ns3.google.com.
google.com NS 7h40m6s 0 ns2.google.com.
google.com NS 7h40m6s 0 ns4.google.com.
google.com MX 10m0s 20 alt1.aspmx.l.google.com.
google.com MX 10m0s 10 aspmx.l.google.com.
google.com MX 10m0s 50 alt4.aspmx.l.google.com.
google.com MX 10m0s 40 alt3.aspmx.l.google.com.
google.com MX 10m0s 30 alt2.aspmx.l.google.com.
[Finished in 2.3s]
Todo
  1. Support more DNS record types

Documentation

Index

Constants

View Source
const (
	TypeA     = QueryType(dns.TypeA)
	TypeAAAA  = QueryType(dns.TypeAAAA)
	TypeNS    = QueryType(dns.TypeNS)
	TypeMX    = QueryType(dns.TypeMX)
	TypeSOA   = QueryType(dns.TypeSOA)
	TypeCNAME = QueryType(dns.TypeCNAME)
	TypeTXT   = QueryType(dns.TypeTXT)
)

Variables

View Source
var Config = Configuration{Timeout: time.Second * time.Duration(2), RetryTimes: uint(0)}

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	Timeout    time.Duration
	RetryTimes uint
}

func (*Configuration) SetTimeout

func (c *Configuration) SetTimeout(seconds uint)

type Query

type Query struct {
	Items []*QueryItem
}

func NewQueryWithTargets

func NewQueryWithTargets(targets ...string) *Query

func (*Query) Count

func (query *Query) Count() int

func (*Query) Types

func (query *Query) Types(types ...QueryType) *Query

type QueryItem

type QueryItem struct {
	Target string
	Types  []QueryType
}

type QueryType

type QueryType uint16

func (QueryType) String

func (q QueryType) String() string

type Resolver

type Resolver struct {
	Server string
	Query  *Query
}

func NewResolver

func NewResolver(server string) *Resolver

func (*Resolver) Lookup

func (r *Resolver) Lookup() *Result

func (*Resolver) Targets

func (r *Resolver) Targets(targets ...string) *Query

type Result

type Result struct {
	Server string
	ResMap map[string][]*ResultItem
}

type ResultItem

type ResultItem struct {
	Record   string
	Type     string
	Ttl      time.Duration
	Priority uint16
	Content  string
}

func Exchange

func Exchange(target string, server string, queryType QueryType) ([]*ResultItem, error)

func NewResultItemWithDnsRR

func NewResultItemWithDnsRR(queryType QueryType, answer dns.RR) (resultItem *ResultItem)

Jump to

Keyboard shortcuts

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