TypeScript DNS packet encoder/decoder with support for 46+ record types, DNSSEC, mDNS, UDP, TCP, DoT, and DoH.
https://gibme-npm.github.io/dns/
yarn add @gibme/dns
or
npm install @gibme/dns
qu (unicast response) and flush (cache purge) bitsUnsupported fallback for unknown typesThe 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);
}
}
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)
}
);
import { Query } from '@gibme/dns';
const query = new Query({
id: 0,
questions: [{
type: 'A',
name: 'google.com'
}]
});
socket.send(query.buffer);
import { Packet } from '@gibme/dns';
const packet = new Packet(buffer);
console.log(packet.id);
console.log(packet.questions);
console.log(packet.answers);
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;
}
}
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);
| 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 |
This library includes comprehensive security hardening to protect against malicious DNS packets. See SECURITY.md for full details.
Key Security Features:
Protocol Limits Enforced: