dnsutil

package module
v0.0.0-...-d015297 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

Go Report Card

dnsutil

Golang DNS dig featureset

Translated version of this repo.

go get github.com/cmpoon/dnsutil
//Normal

package main

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

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

package main

import (
	"fmt"
	"github.com/cmpoon/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/cmpoon/dnsutil"
)

func main() {
    var dig dnsutil.Dig
    dig.Retry=3 //retry  when write or read message return error . defualt 1
    dig.SetDNS("1.1.1.1") //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/cmpoon/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)
	}
}
//Check whether the DNS record has been overridden by non-authoritative means (e.g. ISP blocking)

package main

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

func main() {
	polluted, err := dnsutil.IsPolluted("facebook.com")
	if err != nil {
		fmt.Println(err)
		return
	}
	if polluted {
		fmt.Println("Detected unauthorised alteration to DNS record")
	} else {
		fmt.Println("Normal")
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPolluted

func IsPolluted(domain string) (bool, error)

IsPolluted Returns whether the DNS record has been altered from its authoritative record

func NewMsg

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

NewMsg returns query msg

Types

type Dig

type Dig struct {
	LocalAddr    string
	RemoteAddr   string
	EDNSSubnet   net.IP
	DialTimeout  time.Duration
	WriteTimeout time.Duration
	ReadTimeout  time.Duration
	Protocol     string
	Retry        int
}

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) 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 sends msg, receives reply

func (*Dig) GetMsg

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

GetMsg Returns msg Answer Section

func (*Dig) GetRR

func (d *Dig) GetRR(Type uint16, domain string) ([]dns.RR, error)

GetRR Returns ANSWER SECTION

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) SRV

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

SRV dig srv

func (*Dig) SetDNS

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

SetDNS Sets queried dns server

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 Emulates dig +trace

type TraceResponse

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

TraceResponse dig +trace Reply

Jump to

Keyboard shortcuts

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