doh

package module
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

README

doh.go

License GoDoc Build Status Go Report Card Code Cover

doh-go is a DNS over HTTPS (DoH) Golang client implementation.

Overview

DNS over HTTPS (DoH) is a protocol for performing remote Domain Name System (DNS) resolution via the HTTPS protocol. Specification is RFC 8484 - DNS Queries over HTTPS (DoH).

This module provides a easy way to using DoH as client in golang.

Features

  • DoH client, Simple and Easy to use
  • Support cloudflare, google, quad9 and dnspod
  • Specify the provider you like
  • Auto select fastest provider
  • Enable cache is supported
  • EDNS0-Client-Subnet query supported

Installation

go get -u github.com/likexian/doh-go

Importing

import (
    "github.com/likexian/doh-go"
    "github.com/likexian/doh-go/dns"
)

Documentation

Visit the docs on GoDoc

Example

Select fastest provider and query (Highly Recommend)
// init a context
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

// init doh client, auto select the fastest provider base on your like
// you can also use as: c := doh.Use(), it will select from all providers
c := doh.Use(doh.CloudflareProvider, doh.GoogleProvider)

// do doh query
rsp, err := c.Query(ctx, "likexian.com", dns.TypeA)
if err != nil {
    panic(err)
}

// close the client
c.Close()

// doh dns answer
answer := rsp.Answer

// print all answer
for _, a := range answer {
    fmt.Printf("%s -> %s\n", a.Name, a.Data)
}
Specify DoH provider and query (You are Welcome)
// init a context
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

// init doh client, specify one provider
c := doh.New(Quad9Provider)

// do doh query
rsp, err := c.Query(ctx, "likexian.com", dns.TypeMX)
if err != nil {
    panic(err)
}

// doh dns answer
answer := rsp.Answer

// print all answer
for _, a := range answer {
    fmt.Printf("%s -> %s\n", a.Name, a.Data)
}

Providers

Quad9 (Recommend)

Quad9 is a free, recursive, anycast DNS platform that provides end users robust security protections, high-performance, and privacy.

Cloudflare (Fast)

Cloudflare's mission is to help build a better Internet. We're excited today to take another step toward that mission with the launch of 1.1.1.1 — the Internet's fastest, privacy-first consumer DNS service.

Google (NOT work in Mainland China)

Google Public DNS is a recursive DNS resolver, similar to other publicly available services. We think it provides many benefits, including improved security, fast performance, and more valid results. But it is not work in mainland China.

DNSPod (Fake DoH)

DNS over HTTP but NOT HTTPS and A record only. This is something known as HTTPDNS, provided by DNSPod (Tencent Cloud). The backend is a anycast public DNS platform well known in China.

LICENSE

Copyright 2019 Li Kexian

Licensed under the Apache License 2.0

About

DONATE

Documentation

Index

Constants

View Source
const (
	CloudflareProvider = iota
	DNSPodProvider
	GoogleProvider
	Quad9Provider
)

DoH Providers enum

Variables

DoH Providers list

Functions

func Author

func Author() string

Author returns package author

func License

func License() string

License returns package license

func Version

func Version() string

Version returns package version

Types

type DoH

type DoH struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

DoH is doh client

func Use

func Use(provider ...int) *DoH

Use returns a new DoH client, You can specify one or multiple provider, if multiple, it will try to select the fastest

func (*DoH) Close

func (c *DoH) Close()

Close close doh client

func (*DoH) ECSQuery

func (c *DoH) ECSQuery(ctx context.Context, d dns.Domain, t dns.Type, s dns.ECS) (*dns.Response, error)

ECSQuery do DoH query with the edns0-client-subnet option

func (*DoH) EnableCache

func (c *DoH) EnableCache(cache bool) *DoH

EnableCache enable query cache

func (*DoH) Query

func (c *DoH) Query(ctx context.Context, d dns.Domain, t dns.Type) (*dns.Response, error)

Query do DoH query

type Provider

type Provider interface {
	Query(context.Context, dns.Domain, dns.Type) (*dns.Response, error)
	ECSQuery(context.Context, dns.Domain, dns.Type, dns.ECS) (*dns.Response, error)
	String() string
}

Provider is the provider interface

func New

func New(provider int) Provider

New returns a new DoH client, quad9 is default

Directories

Path Synopsis
provider

Jump to

Keyboard shortcuts

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