tessl install tessl/pypi-dnslib@0.9.0Simple 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%
Build a DNS message builder tool that constructs DNS query and response packets and encodes them to wire format for network transmission.
DNS (Domain Name System) messages are binary packets transmitted over networks. Creating these packets requires encoding DNS records into the proper wire format according to RFC 1035 specifications. Your tool should allow users to construct DNS messages programmatically and output them as binary data suitable for network transmission.
Implement a DNS message builder in dns_builder.py with the following capabilities:
Query Construction: Create a DNS query message for a domain name with a specified record type (e.g., A, AAAA, MX, TXT). The query should include:
Response Construction: Create a DNS response message that includes:
Record Support: Support at least these record types in answers:
Wire Format Encoding: Provide functionality to convert DNS messages to binary wire format suitable for transmission over UDP or TCP.
Create a module with the following functions:
build_query(domain: str, record_type: str) -> bytes: Constructs a DNS query and returns it in wire formatbuild_response(domain: str, record_type: str, answers: list) -> bytes: Constructs a DNS response with the given answers and returns it in wire formatWhere answers is a list of dictionaries containing record data. For example:
{"address": "192.0.2.1", "ttl": 300}{"address": "2001:db8::1", "ttl": 300}{"preference": 10, "exchange": "mail.example.com", "ttl": 300}{"text": "v=spf1 -all", "ttl": 300}from dns_builder import build_query, build_response
# Build a query for an A record
query_bytes = build_query("example.com", "A")
# Returns binary data ready for network transmission
# Build a response with multiple A records
response_bytes = build_response(
"example.com",
"A",
[
{"address": "192.0.2.1", "ttl": 300},
{"address": "192.0.2.2", "ttl": 300}
]
)Python library for DNS packet manipulation and wire format encoding/decoding.
from dns_builder import build_query
# Build query
query_bytes = build_query("example.com", "A")
# Verify it's binary data
assert isinstance(query_bytes, bytes)
assert len(query_bytes) > 0
# Verify it's a valid DNS packet (should start with transaction ID and flags)
assert len(query_bytes) >= 12 # Minimum DNS header sizefrom dns_builder import build_response
# Build response with single A record
response_bytes = build_response(
"example.com",
"A",
[{"address": "192.0.2.53", "ttl": 3600}]
)
# Verify it's binary data
assert isinstance(response_bytes, bytes)
assert len(response_bytes) > 0from dns_builder import build_response
# Build response with MX records
response_bytes = build_response(
"example.com",
"MX",
[
{"preference": 10, "exchange": "mail1.example.com", "ttl": 3600},
{"preference": 20, "exchange": "mail2.example.com", "ttl": 3600}
]
)
# Verify it's binary data
assert isinstance(response_bytes, bytes)
assert len(response_bytes) > 0Create tests in dns_builder.test.py that verify: