You Can Resolve Domains via curl Using DoH
Did you know you can use curl to get DNS information? Here's how:
$ curl -X GET "https://cloudflare-dns.com/dns-query?name=example.com&type=A" -H "Accept: application/dns-json"
{"Status":0,"TC":false,"RD":true,"RA":true,"AD":true,"CD":false,"Question":[{"name":"example.com","type":1}],"Answer":[{"name":"example.com","type":1,"TTL":276,"data":"23.192.228.84"},{"name":"example.com","type":1,"TTL":276,"data":"23.215.0.136"},{"name":"example.com","type":1,"TTL":276,"data":"23.192.228.80"},{"name":"example.com","type":1,"TTL":276,"data":"23.215.0.138"},{"name":"example.com","type":1,"TTL":276,"data":"96.7.128.175"},{"name":"example.com","type":1,"TTL":276,"data":"96.7.128.198"}]}%
It works on Cloudflare's ODOH server too!
$ curl -X GET "https://odoh.cloudflare-dns.com/dns-query?name=example.com&type=A" -H "Accept: application/dns-json"
{"Status":0,"TC":false,"RD":true,"RA":true,"AD":false,"CD":false,"Question":[{"name":"example.com","type":1}],"Answer":[{"name":"example.com","type":1,"TTL":35,"data":"23.192.228.84"},{"name":"example.com","type":1,"TTL":35,"data":"23.215.0.138"},{"name":"example.com","type":1,"TTL":35,"data":"23.215.0.136"},{"name":"example.com","type":1,"TTL":35,"data":"96.7.128.198"},{"name":"example.com","type":1,"TTL":35,"data":"96.7.128.175"},{"name":"example.com","type":1,"TTL":35,"data":"23.192.228.80"}]}%
If you can't bootstrap a DoH server, you can always use https://9.9.9.9/dns-query instead (though not in this format) or https://1.1.1.1/dns-query. If you already know the IP of your target, you can use curl's `–resolve` option too. curl has a `–doh-url` as well which can be used if you want curl to use DoH itself.
Note that although this method works for Cloudlare DoH servers, it is not part of any RFC so you can't really rely on them and should refer to the original RFC instead if you want to send your request to other servers.