A-Record Lookup

Step 1: A-Record Lookup

DNS maps names to records. The most basic is the A record: a name β†’ IPv4 address. The zone (an injected dict of name -> list of records, each {"type", "value", "ttl"}) stands in for authoritative data.

  • resolve(name): return the first A record's value for the name, or None if there's no A record (an NXDOMAIN-style miss)

Ignore non-A record types for now.

Hints
Starter code
import time


class DNSResolver:
    def __init__(self, zone=None, clock=time.time):
        self.zone = zone if zone is not None else {}   # name -> list of records
        self.clock = clock

    def resolve(self, name):
        """Return the first A record value for name, or None."""
        # TODO: pull this name's record list out of self.zone, remembering that
        # a name absent from the zone simply has no records. Scan that list in
        # order and hand back the value of the first record whose type says A.
        # When no A record turns up at all, the answer is a None miss.
        pass
Write it on a laptop

The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.