dnsutil

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: Apache-2.0 Imports: 10 Imported by: 25 modules, 22 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 Report Card

dnsutil

Golang DNS dig功能库
go get github.com/lixiangzhong/dnsutil
//Normal

package main

import (
	"fmt"
	"github.com/lixiangzhong/dnsutil"
)

func main() {
    var dig dnsutil.Dig 
    dig.SetDNS("8.8.8.8") //or ns.xxx.com 
    a, err := dig.A("google.com")  // dig google.com @8.8.8.8
    fmt.Println(a, err)
}
//msg

package main

import (
	"fmt"
	"github.com/lixiangzhong/dnsutil"
	"github.com/miekg/dns"
)

func main() {
	var dig dnsutil.Dig
	dig.SetDNS("1.1.1.1")
	msg, err := dig.GetMsg(dns.TypeA, "google.com")
	if err != nil {
		fmt.Println(err)
		return
	}
	// fmt.Println(msg)
	// or
	fmt.Println(msg.Question) //question section
	fmt.Println(msg.Answer)   //answer section.
	fmt.Println(msg.Ns)       //authority section.
	fmt.Println(msg.Extra)    //additional section.
}

//EDNS0ClientSubnet

package main

import (
	"fmt"
	"github.com/lixiangzhong/dnsutil"
)

func main() {
    var dig dnsutil.Dig
    dig.SetDNS("8.8.8.8") //or ns.xxx.com
    dig.SetEDNS0ClientSubnet("123.123.123.123")   //support edns0clientsubnet
    a, err := dig.A("google.com")  // dig google.com @8.8.8.8 +client=123.123.123.123
    fmt.Println(a, err)
}
//Retry

package main

import (
	"fmt"
	"github.com/lixiangzhong/dnsutil"
)

func main() {
    var dig dnsutil.Dig
    dig.Retry=3 //retry  when write or read message return error . defualt 1
    dig.SetDNS("8.8.8.8") //or ns.xxx.com 
    a, err := dig.A("google.com")  // dig google.com @8.8.8.8
    fmt.Println(a, err)
}
//dig +trace

package main

import (
	"fmt"
	"github.com/lixiangzhong/dnsutil"
)

func main() {
	domain := "google.com"
	var dig dnsutil.Dig
	rsps, err := dig.Trace(domain)  //dig +trace google.com
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, rsp := range rsps {
		if rsp.Msg.Authoritative {
			for _, answer := range rsp.Msg.Answer {
				fmt.Println(answer)
			}
		}
		for _, ns := range rsp.Msg.Ns {
			fmt.Println(ns)
		}
		fmt.Println("\tReceived from", rsp.Server, rsp.ServerIP)
	}
}
//检查是否被污染

package main

import (
	"fmt"
	"github.com/lixiangzhong/dnsutil"
)

func main() {
	polluted, err := dnsutil.IsPolluted("facebook.com")
	if err != nil {
		fmt.Println(err)
		return
	}
	if polluted {
		fmt.Println("被污染,你懂的")
	} else {
		fmt.Println("正常")
	}
}
//SetBackupDNS
//同时向设置的2个DNS发起请求,返回最快响应的那个结果
//Initiate requests to two DNS settings at the same time, returning the fastest response result
package main

import (
	"fmt"
	"github.com/lixiangzhong/dnsutil"
)

func main() {
	var dig dnsutil.Dig
	dig.SetDNS("1.1.1.1")
	dig.SetBackupDNS("8.8.8.8")
	a, err := dig.A("google.com")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(a)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPolluted

func IsPolluted(domain string) (bool, error)

IsPolluted 返回domain是否被污染

func NewMsg

func NewMsg(Type uint16, domain string) *dns.Msg

NewMsg 返回query msg

Types

type Dig

type Dig struct {
	LocalAddr        string
	RemoteAddr       string
	BackupRemoteAddr string
	EDNSSubnet       net.IP
	DialTimeout      time.Duration
	WriteTimeout     time.Duration
	ReadTimeout      time.Duration
	Protocol         string
	Retry            int
	Fallback         bool //if Truncated == true; udp -> tcp
}

Dig dig

func (*Dig) A

func (d *Dig) A(domain string) ([]*dns.A, error)

A dig a

func (*Dig) AAAA

func (d *Dig) AAAA(domain string) ([]*dns.AAAA, error)

AAAA dig aaaa

func (*Dig) At

func (d *Dig) At(host string) error

At 设置查询的dns server,同SetDNS,只是更加语义化

func (*Dig) CAA

func (d *Dig) CAA(domain string) ([]*dns.CAA, error)

CAA dig caa

func (*Dig) CNAME

func (d *Dig) CNAME(domain string) ([]*dns.CNAME, error)

CNAME dig cname

func (*Dig) Exchange

func (d *Dig) Exchange(m *dns.Msg) (*dns.Msg, error)

Exchange 发送msg 接收响应

func (*Dig) GetMsg

func (d *Dig) GetMsg(Type uint16, domain string) (*dns.Msg, error)

GetMsg 返回msg响应体

func (*Dig) MX

func (d *Dig) MX(domain string) ([]*dns.MX, error)

MX dig mx

func (*Dig) NS

func (d *Dig) NS(domain string) ([]*dns.NS, error)

NS dig ns

func (*Dig) PTR

func (d *Dig) PTR(domain string) ([]*dns.PTR, error)

PTR dig ptr

func (*Dig) SPF

func (d *Dig) SPF(domain string) ([]*dns.SPF, error)

SPF dig spf

func (*Dig) SRV

func (d *Dig) SRV(domain string) ([]*dns.SRV, error)

SRV dig srv

func (*Dig) SetBackupDNS

func (d *Dig) SetBackupDNS(host string) error

SetBackupDNS 设置后查询DNS将同时向两个server发起请求,并响应第一个收到的msg

func (*Dig) SetDNS

func (d *Dig) SetDNS(host string) error

SetDNS 设置查询的dns server Deprecated: use At

func (*Dig) SetEDNS0ClientSubnet

func (d *Dig) SetEDNS0ClientSubnet(clientip string) error

SetEDNS0ClientSubnet +client

func (*Dig) SetTimeOut

func (d *Dig) SetTimeOut(t time.Duration)

SetTimeOut set read write dial timeout

func (*Dig) TXT

func (d *Dig) TXT(domain string) ([]*dns.TXT, error)

TXT dig txt

func (*Dig) Trace

func (d *Dig) Trace(domain string) ([]TraceResponse, error)

Trace 类似于 dig +trace

func (*Dig) TraceForRecord

func (d *Dig) TraceForRecord(domain string, msgType uint16) ([]TraceResponse, error)

Trace 类似于 dig +trace -t msqType

func (Dig) UseBackup

func (d Dig) UseBackup() Dig

type TraceResponse

type TraceResponse struct {
	Server   string
	ServerIP string
	Msg      *dns.Msg
}

TraceResponse dig +trace 响应

Jump to

Keyboard shortcuts

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