CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-dnspython

DNS toolkit for Python supporting almost all record types with high-level and low-level DNS operations

85

1.37x
Overview
Eval results
Files

task.mdevals/scenario-6/

Dynamic DNS Update Composer

Builds authenticated DNS UPDATE wire packets that include EDNS configuration.

Capabilities

Builds addition and deletion updates

  • Given zone example.com, addition [('www', 300, 'A', '192.0.2.10')] and deletion [], returns a wire message using the DNS UPDATE opcode whose zone section targets example.com. and whose update section adds an A record for www.example.com. with TTL 300. @test
  • Given zone example.com and deletion ["old.example.com."], returns an UPDATE message whose update section removes existing records for that name using the DNS delete semantics (class NONE, type ANY). @test

Applies EDNS settings

  • When payload size 1232 and an EDNS option with code 8 and IPv4 prefix 203.0.113.5/24 are provided, the message includes a single OPT record reflecting the payload size and encoded option; the option is absent when none are provided. @test

Signs requests with TSIG

  • When given TSIG parameters (key name update-key.example.com., base64 secret, algorithm hmac-sha256, fudge 300), the resulting message includes a TSIG record that validates successfully against those inputs. @test

Provides wire output and metadata

  • The main function returns a tuple of the wire-format bytes and a metadata dict containing the message id, opcode name, and section counts keyed by zone/prereq/update/additional. @test

Implementation

@generates

API

from dataclasses import dataclass
from typing import List, Optional, Tuple, Union, Dict, Any

@dataclass
class RecordChange:
    name: str
    ttl: int
    rtype: str
    rdata: str

@dataclass
class EdnsOption:
    code: int
    value: Union[str, bytes]

@dataclass
class TsigCredentials:
    name: str
    secret_base64: str
    algorithm: str = "hmac-sha256"
    fudge: int = 300

def compose_update(
    zone: str,
    additions: List[RecordChange],
    deletions: List[str],
    edns_payload: Optional[int] = None,
    edns_options: Optional[List[EdnsOption]] = None,
    tsig: Optional[TsigCredentials] = None,
    message_id: Optional[int] = None,
) -> Tuple[bytes, Dict[str, Any]]:
    """
    Builds a DNS UPDATE message that applies the requested record changes,
    optionally sets EDNS payload size and options, optionally signs with TSIG,
    and returns the wire bytes along with basic metadata derived from the message,
    including the id, opcode name, and section counts.
    """

Dependencies { .dependencies }

dnspython { .dependency }

Provides DNS message builders, EDNS option helpers, and TSIG signing utilities.

Install with Tessl CLI

npx tessl i tessl/pypi-dnspython

tile.json