Skip to main content

A utility to parse DNS BIND zone and view files and convert them to CSV format.

Project description

๐ŸŒ DNS BIND Zone & View Parser

Python 3.12+ License: MIT Tests Coverage uv

๐Ÿš€ Transform DNS BIND zone and view files into structured CSV data with ease

A powerful Python CLI tool that parses DNS BIND zone files and view configurations, extracting all DNS records into clean, structured CSV format. Built with modern Python tooling and comprehensive error handling.

โœจ Features

  • ๐ŸŽฏ Comprehensive DNS Support: Handles all standard DNS record types (A, AAAA, CNAME, MX, TXT, NS, SOA, PTR, etc.)
  • ๐Ÿ”„ Smart Fallback Parsing: Gracefully handles unknown record types and malformed entries
  • ๐Ÿ“Š CSV Export: Clean, structured output with standardized columns
  • ๐Ÿ–ฅ๏ธ CLI Interface: Intuitive command-line interface with auto-completion
  • ๐Ÿ” Zone & View Parsing: Supports both zone files and view configurations
  • โšก Fast & Reliable: Built on dnspython with optimized parsing algorithms
  • ๐Ÿงช Well Tested: Comprehensive test suite with 66% coverage

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/your-username/pybind2csv.git
cd pybind2csv

# Install with uv (recommended)
uv sync

# Or install with pip
pip install .

Basic Usage

# Parse a single zone file
uv run pybind2csv parse-single example.zone --zone-name example.com

# Parse zone and view files together
uv run pybind2csv parse-zone example.zone example.vroaming --output dns_records.csv

# Get help
uv run pybind2csv --help

๐Ÿ“‹ Requirements

  • Python: 3.12 or higher
  • Dependencies: Managed automatically via uv or pip
  • OS: Windows, macOS, Linux compatible

๐Ÿ› ๏ธ Usage Guide

CLI Commands

parse-single - Parse Individual Files

uv run pybind2csv parse-single [OPTIONS] FILE

Options:
  --zone-name TEXT    DNS zone name (e.g., example.com)
  --view-name TEXT    DNS view name (e.g., internal, external)
  --output PATH       Output CSV file path
  --verbose          Enable verbose logging

parse-zone - Parse Zone & View Files

uv run pybind2csv parse-zone [OPTIONS] ZONE_FILE VIEW_FILE

Options:
  --output PATH       Output CSV file path [default: output.csv]
  --verbose          Enable verbose logging

Examples

Example 1: Basic Zone Parsing

# Parse a zone file with auto-detected zone name
uv run pybind2csv parse-single tests/example.vlocal --zone-name example.com --view-name local

Example 2: Production Zone & View

# Parse production zone and view files
uv run pybind2csv parse-zone production.zone production.vroaming --output production_dns.csv

Example 3: Verbose Mode

# Get detailed parsing information
uv run pybind2csv parse-single example.zone --zone-name example.com --verbose

๐Ÿ“Š Output Format

The parser generates CSV files with the following standardized columns:

Column Description Example
zone DNS zone name example.com
view DNS view name local
name Record name www
type DNS record type A, AAAA, CNAME, etc.
ttl Time to live 300
data Record data 192.0.2.1

Sample Output

zone,view,name,type,ttl,data
example.com,local,example.com,SOA,300,ns1.example.com. admin.example.com. 2024010101 3600 1800 604800 86400
example.com,local,example.com,NS,300,ns1.example.com.
example.com,local,www,A,300,192.0.2.1
example.com,local,mail,MX,300,10 mail.example.com.

๐Ÿงช Development

Setup Development Environment

# Clone and setup
git clone https://github.com/your-username/pybind2csv.git
cd pybind2csv

# Install with dev dependencies
uv sync --dev

# Run tests
uv run pytest -v --cov=pybind2csv

# Run linting
uv run ruff check .
uv run ruff format .

Project Structure

pybind2csv/
โ”œโ”€โ”€ pybind2csv/
โ”‚   โ”œโ”€โ”€ __init__.py      # Package initialization
โ”‚   โ”œโ”€โ”€ __main__.py      # CLI entry point
โ”‚   โ”œโ”€โ”€ main.py          # CLI commands and interface
โ”‚   โ””โ”€โ”€ parser.py        # Core DNS parsing logic
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_parser.py   # Comprehensive test suite
โ”‚   โ”œโ”€โ”€ example.vlocal   # Sample zone file
โ”‚   โ””โ”€โ”€ example.vroaming # Sample view file
โ”œโ”€โ”€ pyproject.toml       # Project configuration
โ””โ”€โ”€ README.md           # This file

Testing

Run the comprehensive test suite:

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov=pybind2csv --cov-report=html

# Run specific test
uv run pytest tests/test_parser.py::test_parse_zone_file_valid -v

๐Ÿ› Troubleshooting

Common Issues

Unknown Record Types

The parser includes a fallback mechanism for unknown record types. Warnings will be displayed but parsing will continue.

# Example warning
WARNING: Unknown rdatatype 'DSYNC' - using fallback parsing

Large Zone Files

For very large zone files, use verbose mode to monitor progress:

uv run pybind2csv parse-large large.zone --zone-name example.com --verbose

Debug Mode

Enable debug logging for detailed parsing information:

export LOGURU_LEVEL=DEBUG
uv run pybind2csv parse-single example.zone --zone-name example.com

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

Quick Contribution Steps

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run tests: uv run pytest
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • dnspython - The excellent DNS toolkit powering our parsing
  • typer - For the beautiful CLI interface
  • uv - For lightning-fast Python package management

๐Ÿ“ž Support


Made with โค๏ธ by the DNS Community

Transform your DNS data with confidence and precision

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybind2csv-0.1.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybind2csv-0.1.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file pybind2csv-0.1.2.tar.gz.

File metadata

  • Download URL: pybind2csv-0.1.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.25

File hashes

Hashes for pybind2csv-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2108455e8110f61da605245f6bd6e479d577729281da2a569b78d29a482bcb64
MD5 06531c445668ca27f80a7732f120f389
BLAKE2b-256 613abb4c5cefc2a0a3b59907f1371c3127dc929977b597988744a57e24b9ce14

See more details on using hashes here.

File details

Details for the file pybind2csv-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pybind2csv-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c94b58136d2bdf7a7e81a1b2d179bdc86db819f35aeeb2fc5d9e72268ba472e5
MD5 7e025bbe61cb963f59e3acf32ea24f27
BLAKE2b-256 ae57823f397d097152ec6b8231827846ce30fdc757a03c09ea4856c06999cdb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page