Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dns-packet

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dns-packet

An abstract-encoding compliant module for encoding / decoding DNS packets

  • 1.3.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11M
decreased by-14.36%
Maintainers
2
Weekly downloads
 
Created

What is dns-packet?

The dns-packet npm package is a library for encoding/decoding DNS packets. It supports both Node.js and the browser and can handle various DNS record types. It is useful for creating custom DNS servers, clients, or for manipulating DNS packets for analysis or testing.

What are dns-packet's main functionalities?

Encoding DNS packets

This feature allows you to encode a DNS packet into a buffer. The example code shows how to create a DNS query packet for the domain 'example.com'.

const dnsPacket = require('dns-packet');
const encodedPacket = dnsPacket.encode({
  type: 'query',
  id: 1,
  flags: dnsPacket.RECURSION_DESIRED,
  questions: [{
    type: 'A',
    name: 'example.com'
  }]
});

Decoding DNS packets

This feature allows you to decode a DNS packet from a buffer. The example code demonstrates how to decode a buffer into a DNS packet object.

const dnsPacket = require('dns-packet');
const buffer = Buffer.from('...'); // a buffer containing a DNS packet
const decodedPacket = dnsPacket.decode(buffer);

Streaming DNS packet encoding/decoding

This feature allows you to encode and decode DNS packets in a streaming fashion, which is useful for handling DNS packets in a network stream. The example code creates a simple DNS server that responds to all queries with the IP address '127.0.0.1'.

const dnsPacket = require('dns-packet');
const net = require('net');

const server = net.createServer((socket) => {
  socket.pipe(dnsPacket.streamDecode())
    .on('data', (packet) => {
      console.log('received packet:', packet);
      const response = dnsPacket.streamEncode({
        type: 'response',
        id: packet.id,
        questions: packet.questions,
        answers: [{
          type: 'A',
          name: packet.questions[0].name,
          data: '127.0.0.1'
        }]
      });
      socket.write(response);
    });
});

server.listen(53);

Other packages similar to dns-packet

Keywords

FAQs

Package last updated on 26 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc