npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gibme/dns

v22.0.0

Published

TypeScript DNS packet encoder/decoder with support for 46+ record types, DNSSEC, mDNS, UDP, TCP, DoT, and DoH

Readme

@gibme/dns

CI/CD Build Tests NPM License

TypeScript DNS packet encoder/decoder with support for 46+ record types, DNSSEC, mDNS, UDP, TCP, DoT, and DoH.

Documentation

https://gibme-npm.github.io/dns/

Installation

yarn add @gibme/dns

or

npm install @gibme/dns

Requirements

  • Node.js >= 22

Features

  • Transport protocols: UDP (unicast & multicast), TCP, DNS over TLS (DoT), DNS over HTTPS (DoH)
  • Multicast DNS: Full mDNS support with qu (unicast response) and flush (cache purge) bits
  • 46 record type encoders plus an Unsupported fallback for unknown types
  • DNSSEC support: DNSKEY, DS, RRSIG, NSEC, NSEC3, NSEC3PARAM, CDS, CDNSKEY
  • Name compression: RFC 1035 pointer compression with cycle detection
  • Security hardening: Bounds checking, DoS prevention, protocol limit enforcement
  • Automatic TCP fallback: Transparently retries over TCP when a UDP response is truncated
  • TypeScript: Full type definitions with generics

Quick Start

Simple Lookup

The lookup() function handles all transport details, including automatic TCP fallback for truncated UDP responses.

import { lookup } from '@gibme/dns';

const [response, error] = await lookup({
    type: 'A',
    name: 'example.com'
});

if (response) {
    for (const answer of response.answers) {
        console.log(answer.name, answer.type, answer.data);
    }
}

Lookup Options

const [response, error] = await lookup(
    { type: 'MX', name: 'example.com' },
    {
        host: '8.8.8.8',   // nameserver (default: '1.1.1.1')
        port: 53,           // port (default: 53)
        timeout: 5000       // per-query timeout in ms (default: 2000)
    }
);

Encoding a Query

import { Query } from '@gibme/dns';

const query = new Query({
    id: 0,
    questions: [{
        type: 'A',
        name: 'google.com'
    }]
});

socket.send(query.buffer);

Decoding a Packet

import { Packet } from '@gibme/dns';

const packet = new Packet(buffer);

console.log(packet.id);
console.log(packet.questions);
console.log(packet.answers);

Working with Record Data

import { Response } from '@gibme/dns';

const response = new Response(buffer);

for (const answer of response.answers) {
    switch (answer.type) {
        case 'A':
            console.log(`IPv4: ${answer.data}`);
            break;
        case 'MX':
            console.log(`Mail: ${answer.data.exchange} (priority ${answer.data.preference})`);
            break;
        case 'TXT':
            console.log(`Text: ${answer.data.join(' ')}`);
            break;
    }
}

Building a Response

import { Packet } from '@gibme/dns';

const response = new Packet({
    id: 1234,
    type: 1,
    recursion_desired: true,
    recursion_available: true,
    questions: [{ type: 'A', name: 'example.com' }],
    answers: [
        { type: 'A', name: 'example.com', ttl: 300, data: '93.184.216.34' },
        { type: 'AAAA', name: 'example.com', ttl: 300, data: '2606:2800:220:1:248:1893:25c8:1946' }
    ],
    authorities: [],
    additionals: []
});

socket.send(response.buffer);

Supported Record Types

| Type | ID | Description | |------|------|-------------| | A | 1 | IPv4 address | | NS | 2 | Authoritative name server | | CNAME | 5 | Canonical name alias | | SOA | 6 | Start of authority | | PTR | 12 | Pointer for reverse DNS | | HINFO | 13 | Host information | | MX | 15 | Mail exchange | | TXT | 16 | Text strings | | RP | 17 | Responsible person | | AFSDB | 18 | AFS database location | | AAAA | 28 | IPv6 address | | LOC | 29 | Geographic location | | SRV | 33 | Service locator | | NAPTR | 35 | Naming authority pointer | | KX | 36 | Key exchanger | | CERT | 37 | Certificate | | DNAME | 39 | Delegation name | | OPT | 41 | EDNS(0) options | | DS | 43 | Delegation signer (DNSSEC) | | SSHFP | 44 | SSH fingerprint | | IPSECKEY | 45 | IPsec public key | | RRSIG | 46 | RR signature (DNSSEC) | | NSEC | 47 | Next secure (DNSSEC) | | DNSKEY | 48 | DNS public key (DNSSEC) | | DHCID | 49 | DHCP identifier | | NSEC3 | 50 | Next secure v3 (DNSSEC) | | NSEC3PARAM | 51 | NSEC3 parameters (DNSSEC) | | TLSA | 52 | TLS authentication (DANE) | | SMIMEA | 53 | S/MIME certificate association | | HIP | 55 | Host identity protocol | | CDS | 59 | Child DS (DNSSEC) | | CDNSKEY | 60 | Child DNSKEY (DNSSEC) | | OPENPGPKEY | 61 | OpenPGP public key | | CSYNC | 62 | Child-to-parent sync | | ZONEMD | 63 | Zone message digest | | SVCB | 64 | Service binding | | HTTPS | 65 | HTTPS service binding | | EUI48 | 108 | 48-bit MAC address | | EUI64 | 109 | 64-bit EUI address | | TKEY | 249 | Transaction key | | TSIG | 250 | Transaction signature | | URI | 256 | Uniform resource identifier | | CAA | 257 | Certification authority authorization | | AVC | 258 | Application visibility and control | | DOA | 259 | Digital object architecture | | AMTRELAY | 260 | AMT relay discovery | | Unsupported | -- | Raw payload fallback for unknown types |

Security

This library includes comprehensive security hardening to protect against malicious DNS packets. See SECURITY.md for full details.

Key Security Features:

  • Buffer over-read protection with bounds checking
  • DoS prevention (section count limits, TCP message size validation)
  • Compression bomb protection (max depth: 16 levels)
  • Infinite loop detection in record parsing
  • DNS protocol limit enforcement (name length, label length, etc.)

Protocol Limits Enforced:

  • Maximum 100 records per section
  • DNS names must not exceed 255 bytes total
  • Individual labels must not exceed 63 bytes
  • Malformed packets throw descriptive errors

License

MIT