BlastDNS
BlastDNS is an ultra-fast DNS resolver written in Rust. Like massdns, it's designed to be faster the more resolvers you give it. It's both highly efficient and reliable, even if you have shoddy DNS servers. For details, see Architecture.
There are three ways to use it:
BlastDNS is the primary DNS library used by BBOT.
Benchmark
100K DNS lookups against local dnsmasq, with 100 workers:
| Library | Language | Time | QPS | Success | Failed | vs dnspython |
|---|---|---|---|---|---|---|
| massdns | C | 1.687s | 71,898 | 100,000 | 0 | 28.87x |
| blastdns-cli | Rust | 1.732s | 64,942 | 100,000 | 0 | 26.07x |
| blastdns-python | Python | 3.903s | 25,623 | 100,000 | 0 | 10.29x |
| dnspython | Python | 40.149s | 2,491 | 100,000 | 0 | 1.00x |
CLI
The CLI mass-resolves hosts using a specified list of resolvers. It outputs to JSON.
# send all results to jq
|
# print only the raw IPv4 addresses
|
# load from stdin
|
# skip empty responses (e.g., NXDOMAIN with no answers)
|
# skip error responses (e.g., timeouts, connection failures)
|
CLI Help
$ blastdns --help
BlastDNS - Async DNS spray client
Usage: blastdns [OPTIONS] --resolvers <FILE> [HOSTS_TO_RESOLVE]
Arguments:
[HOSTS_TO_RESOLVE] File containing hostnames to resolve (one per line). Reads from stdin if not specified
Options:
--rdtype <RECORD_TYPE>
Record type to query (A, AAAA, MX, ...) [default: A]
--resolvers <FILE>
File containing DNS nameservers (one per line)
--threads-per-resolver <THREADS_PER_RESOLVER>
Worker threads per resolver [default: 2]
--timeout-ms <TIMEOUT_MS>
Per-request timeout in milliseconds [default: 1000]
--retries <RETRIES>
Retry attempts after a resolver failure [default: 10]
--purgatory-threshold <PURGATORY_THRESHOLD>
Consecutive errors before a worker is put into timeout [default: 10]
--purgatory-sentence-ms <PURGATORY_SENTENCE_MS>
How many milliseconds a worker stays in timeout [default: 1000]
--skip-empty
Don't show responses with no answers
--skip-errors
Don't show error responses
--brief
Output brief format (hostname, record type, answers only)
-h, --help
Print help
-V, --version
Print version
Example JSON output
BlastDNS outputs to JSON by default:
Debug Logging
BlastDNS uses the standard Rust tracing ecosystem. Enable debug logging by setting the RUST_LOG environment variable:
# Show debug logs from blastdns only
RUST_LOG=blastdns=debug
# Show debug logs from everything
RUST_LOG=debug
# Show trace-level logs for detailed internal behavior
RUST_LOG=blastdns=trace
Valid log levels (from least to most verbose): error, warn, info, debug, trace
Rust API
Installation
# Install CLI tool
# Add library to your project
Usage
use ;
use StreamExt;
use RecordType;
use Duration;
// read DNS resolvers from a file (one per line -> vector of strings)
let resolvers = read_to_string
.expect
.lines
.map
.;
// create a new blastdns client with default config
let client = new.await?;
// or with custom config
let mut config = default;
config.threads_per_resolver = 5;
config.request_timeout = from_secs;
let client = with_config.await?;
// resolve: lookup a domain, returns only the rdata strings
let answers = client.resolve.await?;
for answer in answers
// resolve_full: lookup a domain, returns the full DNS response
let result = client.resolve_full.await?;
println!;
// resolve_batch: process many hosts in parallel, returns simplified output
// streams back (host, record_type, Vec<rdata>) tuples as they complete
// automatically filters out errors and empty responses
let wordlist = ;
let mut stream = client.resolve_batch;
while let Some = stream.next.await
// resolve_batch_full: process many hosts with full DNS response structures
// streams back (host, Result<response>) tuples with configurable filtering
let wordlist = ;
let mut stream = client.resolve_batch_full;
while let Some = stream.next.await
// resolve_multi: resolve multiple record types for a single host
// returns only successful results with answers as dict[record_type, Vec<rdata>]
let record_types = vec!;
let results = client.resolve_multi.await?;
for in results
// resolve_multi_full: resolve multiple record types with full responses
// returns all results (success and failure) as dict[record_type, Result<response>]
let record_types = vec!;
let results = client.resolve_multi_full.await?;
for in results
MockBlastDNSClient for Testing
MockBlastDNSClient implements the DnsResolver trait and provides a drop-in replacement that returns fabricated DNS responses without making real network requests.
use ;
use RecordType;
use HashMap;
// Create a mock client
let mut mock_client = new;
// Configure mock responses
let responses = from;
// Hosts that should return NXDOMAIN
let nxdomains = vec!;
mock_client.mock_dns;
// Use like any DnsResolver
let answers = mock_client.resolve.await?;
assert_eq!;
// NXDOMAIN hosts return empty responses
let answers = mock_client.resolve.await?;
assert_eq!;
MockBlastDNSClient supports all DnsResolver methods including resolve, resolve_full, resolve_batch, resolve_batch_full, resolve_multi, and resolve_multi_full.
Python API
The blastdns Python package is a thin wrapper around the Rust library.
Installation
# Using pip
# Using uv
# Using poetry
Development Setup
# install python dependencies
# build and install the rust->python bindings
# run tests
Usage
To use it in Python, you can use the Client class:
=
=
# resolve: lookup a single host, returns only rdata strings
= await
# e.g., "93.184.216.34"
# resolve_full: lookup a single host, returns full DNS response as Pydantic model
= await
# resolve_batch: simplified batch resolution with minimal output
# returns only (host, record_type, list[rdata]) - no full DNS response structures
# automatically filters out errors and empty responses
=
# e.g., "93.184.216.34" for A records
# resolve_batch_full: process many hosts in parallel with full responses
# streams results back as they complete
=
# resolve_multi: resolve multiple record types for a single host in parallel
# returns only successful results with answers
=
= await
# resolve_multi_full: resolve multiple record types with full response data
=
= await
Python API Methods
-
Client.resolve(host, record_type=None) -> list[str]: Lookup a single hostname, returning only rdata strings. Defaults toArecords. Returns a list of strings (e.g.,["93.184.216.34"]for A records). Perfect for simple use cases where you just need the record data without the full DNS response structure. -
Client.resolve_full(host, record_type=None) -> DNSResult: Lookup a single hostname, returning the full DNS response. Defaults toArecords. Returns a PydanticDNSResultmodel with typed fields for easy access to headers, queries, answers, etc. -
Client.resolve_batch(hosts, record_type=None): Simplified batch resolution that returns only the essential data. Takes an iterable of hostnames and streams back(host, record_type, answers)tuples whereanswersis a list of rdata strings (e.g.,["93.184.216.34"]for A records,["10 aspmx.l.google.com."]for MX records). Automatically filters out errors and empty responses. Perfect for processing large lists of hosts efficiently. -
Client.resolve_batch_full(hosts, record_type=None, skip_empty=False, skip_errors=False): Resolve many hosts in parallel with full DNS responses. Takes an iterable of hostnames and streams back(host, result)tuples as results complete. Each result is either aDNSResultorDNSErrorPydantic model. Setskip_empty=Trueto filter out successful responses with no answers. Setskip_errors=Trueto filter out error responses. -
Client.resolve_multi(host, record_types) -> dict[str, list[str]]: Resolve multiple record types for a single hostname in parallel, returning only successful results with answers. Takes a list of record type strings (e.g.,["A", "AAAA", "MX"]) and returns a dictionary mapping record types to lists of rdata strings. Only includes record types that resolved successfully and have answers. -
Client.resolve_multi_full(host, record_types) -> dict[str, DNSResultOrError]: Resolve multiple record types for a single hostname in parallel, returning full DNS responses. Takes a list of record type strings and returns a dictionary keyed by record type. Each value is either aDNSResult(success) orDNSError(failure) Pydantic model. Includes all record types, even those that failed or had no answers.
MockClient for Testing
MockClient provides a drop-in replacement for Client that returns fabricated DNS responses without making real network requests. It implements the same interface as Client and is useful for testing code that depends on DNS lookups.
"""Create a mock client with pre-configured test data."""
=
return
# resolve() returns simple rdata strings
= await
assert ==
# resolve_full() returns full DNS response structure
= await
assert
assert == 1
# NXDOMAIN hosts return empty responses (not errors)
= await
assert == 0
# resolve_batch() works with all mocked hosts
# ["93.184.216.34"]
# resolve_multi() resolves multiple record types in parallel
= await
assert == 3
assert ==
Key Features:
- Supports all
Clientmethods:resolve,resolve_full,resolve_batch,resolve_batch_full,resolve_multi,resolve_multi_full - Returns the same data structures as
Clientfor drop-in compatibility - NXDOMAIN hosts (specified in
_NXDOMAINlist) return empty responses, not errors - Unmocked hosts also return empty responses
- Auto-formats PTR queries (IP addresses → reverse DNS format) just like the real client
Response Models
The *_full() methods return Pydantic V2 models for type safety and IDE autocomplete:
DNSResult: Successful DNS response withhostandresponsefieldsDNSError: Failed DNS lookup with anerrorfieldResponse: DNS message withheader,queries,answers,name_servers, etc.
The base methods (resolve, resolve_batch, resolve_multi) return simple Python types (lists, dicts, strings) for convenience when you don't need the full response structure.
ClientConfig exposes the knobs shown above (threads_per_resolver, request_timeout_ms, max_retries, purgatory_threshold, purgatory_sentence_ms) and validates them before handing them to the Rust core.
Architecture
BlastDNS is built on top of hickory-dns, but only makes use of the low-level Client API, not the Resolver API.
Beneath the hood of the BlastDNSClient, each resolver gets its own ResolverWorker tasks, with a configurable number of workers per resolver (default: 2, configurable via BlastDNSConfig.threads_per_resolver).
When a user calls BlastDNSClient::resolve, a new WorkItem is created which contains the request (host + rdtype) and a oneshot channel to hold the result. This WorkItem is put into a crossfire MPMC queue, to be picked up by the first available ResolverWorker. Workers are spawned lazily when the first request is made.
Retry Logic and Fault Tolerance
BlastDNS handles unreliable resolvers through a multi-layered retry system:
Client-Level Retries: When a query fails with a retryable error (network timeouts, connection failures), the client automatically retries up to max_retries times (default: 10). Each retry creates a fresh WorkItem and sends it back to the shared queue, where it can be picked up by any available worker—not necessarily the same resolver. This means retries naturally route around problematic resolvers.
Purgatory System: Each worker tracks consecutive errors. After hitting purgatory_threshold failures (default: 10), the worker enters "purgatory"—it sleeps for purgatory_sentence milliseconds (default: 1000ms) before resuming work. This temporarily sidelines struggling resolvers without removing them entirely, allowing the system to self-heal if resolver issues are transient.
Non-Retryable Errors: Configuration errors (invalid hostnames) and system errors (queue closed) fail immediately without retry, preventing wasted work on queries that can't succeed.
This architecture ensures maximum accuracy even with a mixed pool of reliable and unreliable DNS servers, as queries naturally migrate toward responsive resolvers while problematic ones throttle themselves.
Testing
BlastDNS has two types of tests:
Unit Tests (No DNS Server Required)
Unit tests use MockBlastDNSClient (Rust) or MockClient (Python) and run without any external dependencies:
# Rust unit tests
# Python unit tests
Integration Tests (Require DNS Server)
Integration tests verify real DNS resolution against a local dnsmasq server running on 127.0.0.1:5353 and [::1]:5353.
Install dnsmasq:
Start the test DNS server:
Run integration tests:
# Rust integration tests (marked with #[ignore])
# Python integration tests with real DNS
When done, stop the test DNS server:
Linting
Rust
# Run clippy for lints
# Run rustfmt for formatting
Python
# Run ruff for lints
# Run ruff for formatting