or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/dnslib@0.9.x
tile.json

tessl/pypi-dnslib

tessl install tessl/pypi-dnslib@0.9.0

Simple library to encode/decode DNS wire-format packets

Agent Success

Agent success rate when using this tile

97%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.76x

Baseline

Agent success rate without this tile

55%

task.mdevals/scenario-7/

DNS Zone File Parser

Build a Python utility that parses DNS zone file entries and creates DNS resource records.

Requirements

Your program should read DNS zone file format text and create DNS resource records. Implement these capabilities:

  1. Parse Zone Records: Read zone file format strings (e.g., "example.com. 3600 IN A 192.0.2.1") and create resource record objects
  2. Support Multiple Types: Handle A (IPv4), AAAA (IPv6), CNAME, and MX record types
  3. Zone Format Output: Convert resource records back to zone file format text
  4. Wire Format Encoding: Encode resource records to DNS wire format bytes

Input Format

Zone file format entries follow this pattern:

<name> <ttl> <class> <type> <rdata>

Example inputs:

example.com. 3600 IN A 192.0.2.1
www.example.com. 3600 IN CNAME example.com.
mail.example.com. 3600 IN MX 10 mailserver.example.com.
example.com. 3600 IN AAAA 2001:db8::1

Expected Behavior

For each zone file entry, your program should:

  1. Parse the entry into a resource record object
  2. Convert the record back to zone format (should match original format)
  3. Encode the record to wire format bytes
  4. Report the wire format byte length

Test Cases

  • Parsing an A record with IPv4 address 192.0.2.1 creates a record that outputs "example.com. 3600 IN A 192.0.2.1" in zone format @test
  • Parsing an AAAA record with IPv6 address 2001:db8::1 creates a record with proper IPv6 data @test
  • Parsing a CNAME record creates a record that references the canonical name correctly @test
  • Parsing an MX record with preference 10 creates a record with both preference and mail server data @test

Implementation

@generates

API

def parse_zone_record(zone_line: str):
    """
    Parse a DNS zone file format line and return a DNS resource record.

    Args:
        zone_line: A string containing a single zone file record entry

    Returns:
        A DNS resource record object

    Raises:
        ValueError: If the zone line format is invalid
    """
    pass

def record_to_zone_format(record) -> str:
    """
    Convert a DNS resource record to zone file format string.

    Args:
        record: A DNS resource record object

    Returns:
        String representation in zone file format
    """
    pass

def record_to_wire_format(record) -> bytes:
    """
    Convert a DNS resource record to DNS wire format bytes.

    Args:
        record: A DNS resource record object

    Returns:
        Bytes in DNS wire format
    """
    pass

def verify_round_trip(zone_line: str) -> bool:
    """
    Verify that a zone file line can be parsed, packed, and unparsed correctly.

    Args:
        zone_line: A string containing a single zone file record entry

    Returns:
        True if round-trip conversion preserves the record data
    """
    pass

Dependencies { .dependencies }

dnslib { .dependency }

Provides DNS packet encoding/decoding and resource record support.