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

Custom DNS Geo-Resolver

Build a custom DNS resolver that returns different IP addresses based on the geographic region of the requester. The resolver should implement region-specific responses with failover support.

Requirements

Your custom resolver should:

  1. Extend the appropriate base class to create a DNS resolver
  2. Accept configuration mapping domains to region-specific IP addresses
  3. Determine the region from the client's request handler
  4. Return the appropriate IP address based on the region
  5. Provide failover to a default IP if the region is not configured
  6. Handle both A record queries and return NXDOMAIN for unsupported query types

Region Configuration Format

The resolver should accept configuration in this format:

config = {
    "service.example.com.": {
        "us-east": "192.168.1.10",
        "us-west": "192.168.1.20",
        "eu": "192.168.1.30",
        "default": "192.168.1.1"
    },
    "api.example.com.": {
        "us-east": "192.168.2.10",
        "eu": "192.168.2.30",
        "default": "192.168.2.1"
    }
}

Region Detection

For this implementation, simulate region detection by examining the client address from the handler:

  • Addresses starting with "10.1." are in "us-east"
  • Addresses starting with "10.2." are in "us-west"
  • Addresses starting with "10.3." are in "eu"
  • All other addresses use the "default" region

Implementation

@generates

API

class GeoResolver:
    """
    Custom DNS resolver that returns region-specific IP addresses.

    Args:
        config (dict): Mapping of domains to region-specific IPs
        ttl (int, optional): TTL for DNS responses (default: 300)
    """
    def __init__(self, config, ttl=300):
        """Initialize the geo resolver with configuration."""
        pass

    def resolve(self, request, handler):
        """
        Resolve DNS query with region-specific response.

        Args:
            request: DNS query request
            handler: Request handler with client information

        Returns:
            DNS response with appropriate record or NXDOMAIN
        """
        pass

    def get_region(self, client_address):
        """
        Determine region from client address.

        Args:
            client_address (str): Client IP address

        Returns:
            str: Region identifier
        """
        pass

Test Cases

Basic Region Routing

  • When a client from us-east (10.1.x.x) queries service.example.com, it receives 192.168.1.10 @test
  • When a client from us-west (10.2.x.x) queries service.example.com, it receives 192.168.1.20 @test
  • When a client from eu (10.3.x.x) queries service.example.com, it receives 192.168.1.30 @test

Failover Behavior

  • When a client from an unknown region queries service.example.com, it receives the default IP 192.168.1.1 @test
  • When a client queries api.example.com from us-west (which is not configured for api), it receives the default IP 192.168.2.1 @test

Query Type Handling

  • When a client queries for an AAAA record, the resolver returns NXDOMAIN @test
  • When a client queries for a domain not in the configuration, the resolver returns NXDOMAIN @test

Dependencies { .dependencies }

dnslib { .dependency }

Provides DNS protocol support and server framework.