Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Libdns Laravel Package

daverandom/libdns

Pure-PHP DNS message library for building, parsing, and manipulating DNS packets. Create queries and responses, work with resource records, headers, questions, and sections, and encode/decode wire format for custom resolvers, servers, and network tools.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install via Composer: composer require daverandom/libdns
  • Primary entry points are Resolver (for queries) and MessageBuilder/MessageParser (for constructing/parsing DNS messages)
  • Start with Resolver::resolve($domain, DNS::TYPE_A) to perform a simple A record lookup synchronously
  • Check the README for basic examples—focus on the Resolver class and its resolve() method, which handles query construction and transport (UDP/TCP/TLS) automatically
  • For async or non-blocking usage (e.g., with ReactPHP), use the Async\Resolver adapter (if bundled) or integrate manually via ReactPHP’s event loop

Implementation Patterns

  • Caching Layer Integration: Wrap the Resolver with PSR-16 or PSR-6 cache adapters to reduce DNS load and latency—especially important for CLI tools or services making repeated lookups for the same domain
  • Custom DNS Transport: Override default transports by injecting a custom TransportInterface implementation (e.g., for testing with a mock server, or enforcing DoH/DoT endpoints)
  • Domain Validation & Filtering: Use parsed Record objects to programmatically inspect TTLs, priorities (MX), or security-relevant records (e.g., verify DMARC via _dmarc TXT records)
  • Build-Time DNS Checks: Integrate in CI pipelines to preflight domain configurations (e.g., confirm SPF, DKIM, and DMARC records exist before deployment)
  • Custom Record Types: Extend with MessageBuilder to craft and send arbitrary queries (e.g., TYPE=65 for HTTPS records) without relying on external tools like dig

Gotchas and Tips

  • No built-in resolution of CNAME chains: The resolver does not automatically follow CNAME or DNAME records—you must manually handle redirection by inspecting the response and re-resolving
  • UDP packet size limits: Avoid large UDP responses (>512 bytes) without enabling EDNS0—configure Resolver with EdnsOptions or force TCP fallback if needed
  • Testing pitfalls: Mock DNS responses using Parser on raw binary (e.g., via @covers fixtures), not by mocking Resolver directly—actual DNS parsing is nontrivial and often misestimated
  • Time-sensitive record caches: The library is not a caching resolver—TTLs in responses are returned but not enforced. Implement your own TTL tracking or re-resolve logic
  • IPv6 support: While the library supports AAAA records, ensure your environment (especially CLI) can bind to IPv6 sockets if resolver defaults are used; explicitly configure Transport to prefer IPv4 if needed
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport