Skip to content

Latest commit

History

History
606 lines (454 loc) · 15 KB

File metadata and controls

606 lines (454 loc) · 15 KB

DNS Benchmarking Tool - Example Usage

Comprehensive usage guide with practical examples for all CLI commands and workflows.


Table of Contents


Quick Start

# 1. Activate virtual environment
venv\Scripts\activate # Windowssource venv/bin/activate # Linux/Mac# 2. Verify installation
python dns_benchmark.py --help
# 3. Fetch blocklists
python dns_benchmark.py fetch blocklists
# 4. Run quick test
python dns_benchmark.py test --quick
# 5. View reports in reports/ directory

Blocklist Management

Fetch Blocklists

# Fetch default categories (ads, malware, adult, gambling)
python dns_benchmark.py fetch blocklists
# Fetch specific categories
python dns_benchmark.py fetch blocklists --categories ads --categories malware
# Fetch all available categories
python dns_benchmark.py fetch blocklists --all
# Force refresh cache (bypass 24-hour expiry)
python dns_benchmark.py fetch blocklists --refresh
# Dry run - preview what would be downloaded
python dns_benchmark.py fetch blocklists --dry-run

Available Categories

CategoryDescriptionSources
adsAdvertising domainsStevenBlack, AdGuard, OISD, hagezi
malwareMalware & phishingURLhaus, Phishing Army, ThreatFox
adultAdult contentStevenBlack Porn, BlocklistProject
gamblingGambling sitesStevenBlack, BlocklistProject
trackingTrackers & analyticsEasyPrivacy, hagezi TIF

Cache Operations

# View cache statistics and blocklist info
python dns_benchmark.py fetch cache-info
# Clear all cached blocklists
python dns_benchmark.py fetch clear-cache
# Clear specific category cache
python dns_benchmark.py fetch clear-cache --categories ads

DNS Service Operations

List Configured Services

# Show all configured DNS services
python dns_benchmark.py services list
# Show only filtered DNS services
python dns_benchmark.py services list --filtered-only
# Show only unfiltered (baseline) services
python dns_benchmark.py services list --unfiltered-only

Test Individual Queries

# Test if a service blocks a domain
python dns_benchmark.py services test"Quad9 Filtered" facebook.com
# Test with specific query type (A, AAAA, CNAME, MX, TXT)
python dns_benchmark.py services test"AdGuard DNS" tracker.example.com --query-type AAAA
# Test against ad domain
python dns_benchmark.py services test"AdGuard DNS" ads.google.com
# Test against unfiltered baseline
python dns_benchmark.py services test"Google DNS" ads.google.com

Available DNS Services

Unfiltered (Baseline)

  • Google DNS (8.8.8.8) - UDP
  • Cloudflare DNS (1.1.1.1) - UDP
  • Quad9 Unfiltered (9.9.9.10) - UDP
  • Cloudflare DoH - DNS over HTTPS

Filtered Services

  • Cloudflare Family (1.1.1.3) - Blocks malware + adult
  • Cloudflare Malware Only (1.1.1.2) - Blocks malware
  • Quad9 Filtered (9.9.9.9) - Blocks malware + phishing
  • AdGuard DNS (94.140.14.14) - Blocks ads + trackers
  • AdGuard Family (94.140.14.15) - Blocks ads + trackers + adult
  • CleanBrowsing Family (185.228.168.168) - Family filter
  • OpenDNS FamilyShield (208.67.222.123) - Adult filter
  • Control D (76.76.2.0) - Multiple filter options
  • Mullvad DNS (194.242.2.3) - Privacy + ad blocking
  • NextDNS (45.90.28.0) - Configurable filtering
  • DNS0.eu (193.110.81.0) - GDPR compliant

IPv6 Services

  • Google DNS IPv6 (2001:4860:4860::8888)
  • Cloudflare IPv6 (2606:4700:4700::1111)
  • Quad9 Filtered IPv6 (2620:fe::fe)
  • AdGuard Family IPv6 (2a10:50c0::bad1:ff)

Benchmarking

Quick Test

# Fast test with 10 domains (for verification)
python dns_benchmark.py test --quick
# Quick test with ALL servers and ALL categories
python dns_benchmark.py test --all --quick

Standard Benchmark

# Run full benchmark with defaults# - 100 domains per category# - All default categories (ads, malware, adult, gambling)# - All filtered services# - Baseline comparison enabled# - False positive testing enabled
python dns_benchmark.py test

Custom Benchmark Configurations

# Test specific categories only
python dns_benchmark.py test --categories ads --categories malware
# Test specific services only
python dns_benchmark.py test --services "Quad9 Filtered" --services "AdGuard DNS"# Test with more domains per category
python dns_benchmark.py test --domains 200
# Skip baseline comparison (faster, fewer queries)
python dns_benchmark.py test --no-baseline
# Skip false positive testing
python dns_benchmark.py test --no-legitimate
# Comprehensive scan: ALL DNS servers × ALL blocklist categories
python dns_benchmark.py test --all
# Quick comprehensive scan (10 domains per category)
python dns_benchmark.py test --all --quick

Output Format Options

# Generate HTML report only
python dns_benchmark.py test --output-format html
# Generate multiple formats
python dns_benchmark.py test --output-format html --output-format json --output-format csv
# All format options: html, json, csv, md
python dns_benchmark.py test -f html -f json -f csv -f md

Complete Benchmark Example

# Full custom benchmark with all options
python dns_benchmark.py test \
--categories ads \
--categories malware \
--categories tracking \
--services "Quad9 Filtered" \
--services "AdGuard DNS" \
--services "Cloudflare Family" \
--domains 150 \
--output-format html \
--output-format json

CLI Options Reference

OptionShortDefaultDescription
--categories-catAll defaultCategories to test
--services-sAll filteredSpecific services to test
--domains-n100Domains per category
--no-baselineFalseSkip baseline comparison
--no-legitimateFalseSkip false positive testing
--quickFalseQuick test (10 domains)
--allFalseTest ALL DNS servers with ALL categories
--output-format-fhtml, jsonReport formats

Service Comparison

Compare Against Baseline

# Compare filtered services against Google DNS baseline
python dns_benchmark.py compare -b "Google DNS" -t "Quad9 Filtered" -t "AdGuard DNS"# Compare with Cloudflare as baseline
python dns_benchmark.py compare -b "Cloudflare DNS" -t "Cloudflare Family" -t "OpenDNS FamilyShield"# Compare multiple ad-blocking services
python dns_benchmark.py compare \
-b "Google DNS" \
-t "AdGuard DNS" \
-t "NextDNS" \
-t "Mullvad Ad Block"

Category-Specific Comparison

# Compare ad blocking effectiveness
python dns_benchmark.py compare \
-b "Google DNS" \
-t "AdGuard DNS" \
-t "Quad9 Filtered" \
--categories ads \
--domains 200
# Compare family safety filters
python dns_benchmark.py compare \
-b "Cloudflare DNS" \
-t "AdGuard Family" \
-t "CleanBrowsing Family" \
-t "OpenDNS FamilyShield" \
--categories adult \
--categories gambling

Report Management

List Previous Runs

# Show last 10 benchmark runs
python dns_benchmark.py report list
# Show more history
python dns_benchmark.py report list --limit 25
# Show all runs
python dns_benchmark.py report list --limit 100

Regenerate Reports from History

# Generate report from specific run ID
python dns_benchmark.py report generate --run-id 5 --format html
# Generate from latest run
python dns_benchmark.py report generate --latest --format html
# Generate multiple formats with charts
python dns_benchmark.py report generate --run-id 5 --format html --format json --charts
# Generate all formats
python dns_benchmark.py report generate --latest --format html --format json --format csv --charts

Common Workflows

Workflow 1: First-Time Setup & Verification

# 1. Activate environment
venv\Scripts\activate
# 2. Check available services
python dns_benchmark.py services list
# 3. Fetch all blocklists
python dns_benchmark.py fetch blocklists
# 4. View blocklist cache info
python dns_benchmark.py fetch cache-info
# 5. Run quick test to verify setup
python dns_benchmark.py test --quick
# 6. Check generated reports
dir reports\

Workflow 2: Regular Benchmarking Session

# 1. Refresh blocklists (if needed)
python dns_benchmark.py fetch blocklists --refresh
# 2. Run comprehensive benchmark
python dns_benchmark.py test --domains 150
# 3. View results in browser
start reports\benchmark_*.html

Workflow 3: Ad Blocker Evaluation

# 1. Fetch ad-specific blocklists
python dns_benchmark.py fetch blocklists --categories ads --categories tracking
# 2. Test ad-blocking services specifically
python dns_benchmark.py test \
--categories ads \
--categories tracking \
--services "AdGuard DNS" \
--services "NextDNS" \
--services "Mullvad Ad Block" \
--domains 200
# 3. Compare against unfiltered baseline
python dns_benchmark.py compare \
-b "Google DNS" \
-t "AdGuard DNS" \
-t "NextDNS" \
--categories ads

Workflow 4: Family Safety DNS Evaluation

# 1. Fetch family-relevant blocklists
python dns_benchmark.py fetch blocklists --categories adult --categories gambling
# 2. Test family-focused DNS services
python dns_benchmark.py test \
--categories adult \
--categories gambling \
--services "AdGuard Family" \
--services "CleanBrowsing Family" \
--services "OpenDNS FamilyShield" \
--services "Cloudflare Family" \
--domains 100
# 3. Generate detailed comparison
python dns_benchmark.py compare \
-b "Google DNS" \
-t "AdGuard Family" \
-t "CleanBrowsing Family" \
-t "OpenDNS FamilyShield" \
--categories adult

Workflow 5: Security-Focused Evaluation

# 1. Fetch malware/phishing blocklists
python dns_benchmark.py fetch blocklists --categories malware
# 2. Test security-focused DNS services
python dns_benchmark.py test \
--categories malware \
--services "Quad9 Filtered" \
--services "Cloudflare Malware Only" \
--services "CleanBrowsing Security" \
--services "Comodo Secure" \
--domains 200

Workflow 6: DoH (DNS over HTTPS) Testing

# Test encrypted DNS services
python dns_benchmark.py test \
--services "Cloudflare DoH" \
--services "Google DoH" \
--services "Quad9 DoH" \
--services "AdGuard DoH" \
--categories ads \
--categories malware

Configuration Reference

Configuration File

Edit config/config.yaml to customize:

# Test settingstest_settings:
queries_per_domain: 3# Queries per domain for statsquery_timeout: 5# Timeout in secondsmax_concurrent: 50# Concurrent query limitquery_delay_ms: 10# Delay between queriesmax_retries: 2# Retry attemptsdomains_per_category: 100# Default domains per categoryfalse_positive_domains: 50# Legitimate domains to test# Report settings reporting:
output_dir: "reports"default_formats: ["html", "json"]include_details: truecharts:
enabled: truetheme: "plotly_dark"# Cache settingscache:
blocklist_dir: "data/blocklists"expiry_hours: 24enabled: true

Verbose Mode

# Enable verbose logging for debugging
python dns_benchmark.py --verbose test --quick
# Use custom config file
python dns_benchmark.py --config path/to/custom-config.yaml test

Advanced Usage

Programmatic Usage (Python API)

fromsrc.blocklistimportBlocklistManagerfromsrc.dnsimportDNSResolver, create_query_engine_from_configfromsrc.testingimportBenchmarkRunnerfromsrc.reportingimportReportGenerator# Initialize componentsblocklist_manager=BlocklistManager()
query_engine=create_query_engine_from_config()
# Load blocklistsblocklist_manager.load_blocklists_sync(categories=["ads", "malware"])
# Run benchmarkrunner=BenchmarkRunner(blocklist_manager, query_engine)
results=runner.run_benchmark_sync(
categories=["ads", "malware"],
domains_per_category=100
)
# Generate reportsgenerator=ReportGenerator()
generator.generate(results, formats=["html", "json"])

Export Domains

fromsrc.blocklistimportBlocklistManagermanager=BlocklistManager()
manager.load_blocklists_sync(categories=["ads"])
# Export to filemanager.export_domains(
output_file="data/ads_domains.txt",
categories=["ads"],
format="txt"# txt, json, or csv
)

Query Engine Direct Usage

fromsrc.dnsimportDNSResolverasyncwithDNSResolver() asresolver:
# Query single serviceresponse=awaitresolver.query_by_name(
domain="example.com",
service_name="Quad9 Filtered"
)
print(f"Blocked: {response.is_blocked}")
print(f"Latency: {response.latency_ms}ms")
# Query all servicesresults=awaitresolver.query_all_services(
domain="ads.example.com",
filtered_only=True
)
forname, responseinresults.items():
print(f"{name}: {'Blocked'ifresponse.is_blockedelse'Allowed'}")

Output Reference

Output Locations

Output TypeLocation
HTML Reportsreports/benchmark_YYYYMMDD_HHMMSS.html
JSON Reportsreports/benchmark_YYYYMMDD_HHMMSS.json
CSV Reportsreports/benchmark_YYYYMMDD_HHMMSS.csv
Markdown Reportsreports/benchmark_YYYYMMDD_HHMMSS.md
Chartsreports/charts/
Databasedata/results.db
Cached Blocklistsdata/blocklists/
Logsdata/dns_benchmark.log

Metrics Explained

MetricDescription
Block Rate% of blocklist domains blocked by the DNS service
False Positive Rate% of legitimate domains incorrectly blocked
Accuracy(True Positives + True Negatives) / Total
PrecisionTrue Positives / (True Positives + False Positives)
RecallTrue Positives / (True Positives + False Negatives)
Latency (avg)Average response time in milliseconds
Latency (P95)95th percentile response time

Troubleshooting

Common Issues

# If imports fail
pip install -r requirements.txt
# If blocklists fail to fetch
python dns_benchmark.py fetch blocklists --refresh
# If DNS queries timeout# Edit config/config.yaml: increase query_timeout# View debug output
python dns_benchmark.py --verbose test --quick

Verify Setup

# Check services are configured
python dns_benchmark.py services list
# Test single query
python dns_benchmark.py services test"Google DNS" google.com
# Check cache status
python dns_benchmark.py fetch cache-info