Skip to content

Instantly share code, notes, and snippets.

@miekg miekg/main.go
Created Mar 17, 2018

Embed
What would you like to do?
DNS over HTTP/2
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/miekg/dns"
)
func main() {
client := &http.Client{}
m := new(dns.Msg)
m.SetQuestion("miek.nl.", dns.TypeDNSKEY)
m.SetEdns0(4096, true)
out, err := m.Pack()
if err != nil {
log.Fatal(err)
}
req, err := http.NewRequest("POST", "https://dns.cloudflare.com:443", bytes.NewReader(out))
if err != nil {
log.Fatal(err)
}
req.Header.Set("content-type", "application/dns-udpwireformat")
req.Header.Set("cache-control", "max-age=128")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
rm := new(dns.Msg)
if err := rm.Unpack(buf); err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", rm)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.