How mohammedaltanib/dnscope works
DNScope is a local, batch-oriented Python analysis pipeline for DNS Internet Background Radiation in PCAP/PCAPNG data. The architecture is file-driven: raw capture files are transformed step-by-step into a merged analytical dataset, then into tables and figures for three research questions.
1. Primary boundary: raw packet data vs. analytical data
- Input starts as compressed archives or PCAP/PCAPNG files from the Cloud Telescope dataset.
- Output ends as Parquet datasets plus CSV tables and PNG charts.
- The repo is centered on moving data across these storage formats rather than serving an API or web UI.
2. Stage 1: packet extraction
- fast_extract.py is the ingest boundary.
- It uses tshark externally to pull DNS-relevant fields from PCAPs into temporary CSV files.
- This stage is where low-level packet captures are reduced to structured event rows.
3. Stage 2: column enrichment and format normalization
- csv_to_parquet_addcols.py converts the extracted CSVs into Parquet.
- It also adds derived fields used later in analysis:
- src_24 for /24 source network aggregation
- eTLD+1 for domain-level grouping
- This is the first semantic normalization layer in the pipeline.
4. Stage 3: dataset consolidation
- merge.py combines all Parquet fragments into one unified merged dataset.
- This merged Parquet file is the main analytical substrate for the rest of the repo.
- The architecture assumes many per-file intermediates feeding one consolidated corpus.
5. Stage 4: analysis engine
- Results.py is the central analysis module and the main reusable entry point.
- It exposes a dnscope_mini(...) function for notebook or script use, and generates the outputs for all three research questions.
- This module reads the merged Parquet and writes summary tables and figures.
6. Research question modules are logical slices, not separate services
- RQ1.py, RQ2.py, and RQ3.py appear to isolate analysis logic per question.
- Their responsibilities map to the README:
- RQ1: DNS share across regions and time
- RQ2: query types and response codes
- RQ3: source networks and geographic distribution
- Results.py likely orchestrates or aggregates these analyses into one run.
7. Visualization boundary
- dnscope_mini_figs.py produces figures from the merged Parquet or downstream tables.
- This is a presentation layer separate from the extraction and transformation stages.
- The repo outputs static PNGs, not interactive dashboards.
8. Output structure is deterministic and file-based
- The pipeline writes into a run directory such as run_out/.
- Two main output families exist:
- tables/ for CSV summaries
- figs/ for charts
- This makes the diagram easy: one input dataset fan-outs into multiple analytical artifacts.
9. Core technologies
- Python is the runtime for all repo scripts.
- Key libraries named in the README shape the architecture:
- pandas for tabular manipulation
- pyarrow for Parquet I/O
- duckdb for efficient local analytical queries
- matplotlib for static figures
- tldextract for domain decomposition
- geoip2 for geographic enrichment
- tshark is an important external dependency for packet decoding.
10. Operational model
- This is not a distributed system or long-running service.
- It is a reproducible offline workflow meant to be run sequentially from the command line or inside Jupyter/Anaconda.
- The main architectural dependency chain is:
raw captures → CSV extraction → enriched Parquet → merged Parquet → tables/figures.
11. Data semantics
- The analysis is DNS-centric rather than general packet analysis.
- The pipeline preserves enough metadata to support time-series counts, query/rcode cross-tabs, source-prefix aggregation, and region-based comparisons.
- Geographic and network grouping are derived analysis dimensions, not raw input properties.
12. What to draw in an architecture diagram
- Show a left-to-right flow with four layers:
- raw PCAP/ZIP sources
- extraction/transformation scripts
- merged Parquet analytical store
- analysis/visualization outputs
- Place Results.py as the main consumer of the merged dataset.
- Treat tshark, geoip2, and tldextract as supporting dependencies on the extraction/analysis boundary, not as standalone subsystems.
Main entry points: Results.py Results · fast_extract.py Fast extract · csv_to_parquet_addcols.py CSV enrich · RQ1.py RQ1
Components 15
Raw inputs
Source captures and external decoding dependency.
- PCAP data · Compressed archives and PCAP/PCAPNG inputs from the Cloud Telescope dataset.
- tshark · External packet decoder used to extract DNS-relevant fields from captures.
Preparation pipeline
Extraction, normalization, and dataset consolidation steps.
- Fast extract · Reads raw captures and produces temporary CSV event rows.
fast_extract.py - CSV enrich · Converts extracted CSVs to Parquet and adds derived columns such as src_24 and eTLD+1.
csv_to_parquet_addcols.py - Merge · Combines per-file Parquet fragments into one unified analytical dataset.
merge.py - Merged Parquet · Main corpus used by downstream analysis and visualization.
Analysis layer
Main analytical entrypoint and question-specific logic.
- Data libs · Core libraries shaping the offline workflow: pandas, pyarrow, duckdb, tldextract, geoip2, matplotlib.
- Results · Central reusable analysis module; orchestrates the run and exposes dnscope_mini(...).
Results.py - RQ1 · DNS share across regions and time.
RQ1.py - RQ2 · Query types and response codes.
- RQ3 · Source networks and geographic distribution.
- Figures · Produces static PNG charts from merged data or downstream tables.
dnscope_mini_figs.py
Outputs
Materialized tables and static figures.
- Tables · Run-directory CSV summaries written for the research questions.
- Figures out · Run-directory static figures produced by the pipeline.
- Run output · Deterministic output tree such as run_out/ containing tables/ and figs/.
Connections 22
- PCAP data → Fast extract: input · Raw captures are read by the extraction stage.
- tshark → Fast extract: decode · tshark performs DNS field extraction for fast_extract.
- Fast extract → CSV enrich: CSV rows · Temporary CSV event rows feed enrichment and Parquet conversion.
- CSV enrich → Merge: Parquet fragments · Enriched per-file Parquet outputs are consolidated.
- Merge → Merged Parquet: write · The merge stage materializes the unified analytical dataset.
- Merged Parquet → Results: read · Results consumes the merged Parquet corpus.
- Data libs → Results: supports · Analysis depends on tabular, query, geo, and plotting libraries.
- Data libs → CSV enrich: supports · Normalization and Parquet conversion use data libraries.
- Merged Parquet → RQ1: analyze · RQ1 computes DNS share by region and time.
- Merged Parquet → RQ2: analyze · RQ2 computes query-type and rcode distributions.
- Merged Parquet → RQ3: analyze · RQ3 computes source-network and geography summaries.
- Results → RQ1: orchestrates · Results coordinates the question-specific analysis modules.
- Results → RQ2: orchestrates · Results coordinates the question-specific analysis modules.
- Results → RQ3: orchestrates · Results coordinates the question-specific analysis modules.
- RQ1 → Tables: write tables · RQ1 contributes CSV summaries.
- RQ2 → Tables: write tables · RQ2 contributes CSV summaries.
- RQ3 → Tables: write tables · RQ3 contributes CSV summaries.
- Merged Parquet → Figures: read · Figure generation consumes the merged dataset or derived tables.
- Results → Figures: triggers · Results coordinates figure generation.
- Figures → Figures out: write figures · Static PNG charts are written to the figures output area.
- Tables → Run output: contained in · CSV summaries live under the run directory.
- Figures out → Run output: contained in · PNG figures live under the run directory.