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-10/

DNS Record Processor

Build a DNS record processing utility that creates and manipulates DNS records for various common record types.

Requirements

Your solution should provide functionality to:

  1. Create DNS resource records for multiple record types including IPv4 addresses, IPv6 addresses, canonical names, pointer records, name servers, text records, mail exchanges, and zone authority information.

  2. Parse DNS records from their textual zone file representation into structured objects.

  3. Generate DNS records in zone file format (textual representation).

  4. Create complete DNS response packets containing multiple resource records in the answer section.

Specifications

Record Creation

The utility must support creating records for the following types:

  • IPv4 address records
  • IPv6 address records
  • Canonical name records (aliases)
  • Pointer records (reverse DNS)
  • Name server records
  • Text records (arbitrary text strings)
  • Mail exchange records (with priority values)
  • Start of authority records (with all required fields: primary nameserver, responsible email, serial, refresh, retry, expire, minimum TTL)

Each record should include a domain name, time-to-live value, and the appropriate record-specific data.

Zone File Parsing

The utility must be able to read DNS records written in standard zone file format and convert them into structured record objects that can be manipulated programmatically.

DNS Response Generation

The utility should be able to construct complete DNS response packets that contain multiple resource records. The response should have:

  • A proper DNS header with appropriate flags
  • A question section matching the query
  • An answer section with one or more resource records
  • Proper encoding for transmission over the network

Test Cases

Test 1: Create and format IPv4 address record { .test }

  • Create an A record for "example.com" pointing to "192.0.2.1" with a TTL of 3600 seconds @test
  • The record should format correctly in zone file notation

Test 2: Create and format mail exchange record { .test }

  • Create an MX record for "example.com" with priority 10 pointing to "mail.example.com" with a TTL of 7200 seconds @test
  • The record should include both the priority and mail server hostname

Test 3: Parse zone file format { .test }

  • Parse a zone file line containing: "example.com. 3600 IN A 192.0.2.1" @test
  • Extract the domain name, TTL, and IP address correctly

Test 4: Create DNS response with multiple records { .test }

  • Create a DNS response for a query asking for "example.com" A records @test
  • Add two A records to the answer section with different IP addresses
  • Verify the response can be encoded to wire format (binary representation)

Implementation

@generates

API

def create_a_record(domain: str, ip_address: str, ttl: int):
    """Create an A (IPv4 address) record."""
    pass

def create_aaaa_record(domain: str, ip_address: str, ttl: int):
    """Create an AAAA (IPv6 address) record."""
    pass

def create_cname_record(domain: str, target: str, ttl: int):
    """Create a CNAME (canonical name) record."""
    pass

def create_ptr_record(domain: str, target: str, ttl: int):
    """Create a PTR (pointer) record."""
    pass

def create_ns_record(domain: str, nameserver: str, ttl: int):
    """Create an NS (name server) record."""
    pass

def create_txt_record(domain: str, text: str, ttl: int):
    """Create a TXT (text) record."""
    pass

def create_mx_record(domain: str, priority: int, mailserver: str, ttl: int):
    """Create an MX (mail exchange) record."""
    pass

def create_soa_record(domain: str, mname: str, rname: str, serial: int,
                     refresh: int, retry: int, expire: int, minimum: int, ttl: int):
    """Create an SOA (start of authority) record."""
    pass

def parse_zone_record(zone_line: str):
    """Parse a DNS record from zone file format."""
    pass

def format_zone_record(record):
    """Format a DNS record as zone file text."""
    pass

def create_dns_response(query_name: str, query_type: str, records: list):
    """Create a DNS response packet with the given records in the answer section."""
    pass

Dependencies { .dependencies }

dnslib { .dependency }

Provides DNS protocol support for encoding, decoding, and manipulating DNS packets and resource records.