Created
March 17, 2018 15:32
-
-
Save miekg/0deda153c0cf1cdfc3c6a35d0df8d675 to your computer and use it in GitHub Desktop.
DNS over HTTP/2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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