← Questions

Stepwise DNS resolver with aliasing

0
AnthropicCodingLast asked May 2026

Build a simplified DNS resolver step by step against a fixed test harness: basic name lookup first, then alias layers on top. Later steps assume the earlier ones work.

  • Level 1: add_record(name, ip), resolve(name): sorted addresses; names are case-insensitive and ignore a trailing dot.
  • Level 2: add_alias(alias, target); a name is either an alias or has addresses; cycles and chains over 16 hops resolve to [].
  • Level 3: ts/ttl on every call and resolve_with_ttl(name, ts) returning (addresses, ttl_left).
  • Level 4: wildcard names like *.example.com; the closest enclosing wildcard answers, an exact name always wins.
class Resolver:
    def add_record(self, name, ip, ts=0, ttl=None): ...
    def add_alias(self, alias, target, ts=0, ttl=None): ...
    def resolve(self, name, ts=0): ...
    def resolve_with_ttl(self, name, ts=0): ...
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding