DNS query not specified or too small

339 views Asked by At

I'm trying to make a python script to test if a server can answer in DNS-over-HTTPS. So, I read this article and try to make the same request but in python :

import requests
r=requests.get("https://cloudflare-dns.com/dns-query?name=example.com&type=A", headers={"accept":"application/dns-message"})
print(r.url)
print(r.headers)
print(r.status_code)

Here is the output

https://cloudflare-dns.com/dns-query?name=example.com&type=A

{'Access-Control-Allow-Origin': '*', 'Vary': 'Accept-Encoding', 'CF-RAY': '48b33f92aec83e4a-ZRH', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Date': 'Tue, 18 Dec 2018 17:11:23 GMT', 'Transfer-Encoding': 'chunked', 'Server': 'cloudflare', 'Connection': 'keep-alive'} 400

If I base me on what's written here, my request is not specified or too small.

Does anyone sees where I'm mistaking?

Thanks

1

There are 1 answers

0
Patrick Mevzek On BEST ANSWER

The form you are using to pass parameters needs application/dns-json as MIME Accept type. Otherwise for application/dns-message you have only a dns key with the value being the full DNS message encoded.

Compare:

 curl -H 'accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=example.com&type=AAAA'

(from https://developers.cloudflare.com/1.1.1.1/dns-over-https/json-format/)

with

curl -H 'accept: application/dns-message' -v 'https://cloudflare-dns.com/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | hexdump

(from https://developers.cloudflare.com/1.1.1.1/dns-over-https/wireformat/)