- Docs
- English EN-US
- English
- 简体中文
- 繁體中文
- 日本語
- 한국어
- العربية
- العربية
- Deutsch
- Español
- Français
- हिंदी
- Bahasa Indonesia
- Italiano
- Nederlands
- Polski
- Português
- Русский
- Türkçe
This article presents two methods to retrieve DNS query results using curl:
Returns DNS responses in JSON, making them easy to parse.
curl -H 'accept: application/dns-json' "https://dns.google/resolve?name=baidu.com&type=A" | jq .
curl -H 'accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=baidu.com&type=A' | jq .
curl -H "accept: application/dns-json" "https://223.5.5.5/resolve?name=baidu.com&type=1" | jq .
curl -H 'accept: application/dns-json' 'https://doh.dns.pub/dns-query?name=baidu.com&type=A' | jq .
# Currently unsupported
Returns binary DNS responses that require further parsing.
curl -H 'accept: application/dns-message' 'https://dns.google/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | hexdump -c
curl -H 'accept: application/dns-message' 'https://cloudflare-dns.com/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | hexdump -c
curl -H 'accept: application/dns-message' "https://dns.alidns.com/dns-query?dns=P8QBAAABAAAAAAAABWJhaWR1A2NvbQAAAQAB" | hexdump -c
curl -H 'accept: application/dns-message' 'https://doh.dns.pub/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | hexdump -c
curl -H 'accept: application/dns-message' 'https://public0.adguardprivate.com/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | hexdump -c
# pip install dnspython
# pip install requests
# Parsing JSON responses
import json
import requests
def query_dns_json(domain="example.com", type="A"):
"""Query DNS using JSON format"""
url = "https://dns.google/resolve"
params = {"name": domain, "type": type}
headers = {"accept": "application/dns-json"}
response = requests.get(url, params=params, headers=headers)
return json.dumps(response.json(), indent=2)
# Parsing Wire Format responses
def query_dns_wire(domain="example.com"):
"""Query DNS using Wire Format"""
import dns.message
import requests
import base64
# Create DNS query message
query = dns.message.make_query(domain, 'A')
wire_format = query.to_wire()
dns_query = base64.b64encode(wire_format).decode('utf-8')
# Send request
url = "https://dns.google/dns-query"
params = {"dns": dns_query}
headers = {"accept": "application/dns-message"}
response = requests.get(url, params=params, headers=headers)
dns_response = dns.message.from_wire(response.content)
return str(dns_response)
if __name__ == "__main__":
print("JSON query result:")
print(query_dns_json())
print("\nWire Format query result:")
print(query_dns_wire())
# pip install dnspython
import base64
import dns.message
import dns.rdatatype
# Create a DNS query message
query = dns.message.make_query('example.com', dns.rdatatype.A)
# Convert message to Wire Format
wire_format = query.to_wire()
# Encode to base64
wire_format_base64 = base64.b64encode(wire_format).decode('utf-8')
# Print
print(wire_format_base64)