🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

dhcpd.js

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dhcpd.js

NodeJS implementation of a DHCP server

1.0.2
latest
Source
npm
Version published
Weekly downloads
18
-14.29%
Maintainers
0
Weekly downloads
 
Created
Source

dhcpd.js

dhcpd.js is a Node.js implementation of a DHCP server. It provides a simple and efficient way to handle DHCP events in your network.

license Node.js CI npm version

NPM

Installation

You can install dhcpd.js using npm:

npm install dhcpd.js

Monitor Example

const { Server } = require('dhcpd.js');

const s = new Server('192.168.1.1');

s.on("dhcp", (e) => {
  console.log(e.packet.debug());
});

s.bind();

Server Example

const { BOOTMessageType, Server } = require('dhcpd.js');

const s = new Server({
  serverId: "192.168.1.1",
  gateways: ["192.168.1.1"],
  domainServer: ["192.168.1.1"]
});

s.on("listening", () => {
  console.log("Server start", s.address);
});

const ips = {};

s.on("discover", (e) => {
  const { packet } = e;
  console.log(packet.log());

  let ip = "0.0.0.0";
  if (Object.keys(ips).includes(packet.chaddr)) {
    ip = ips[packet.chaddr];
  } else {
    ip = `192.168.1.${Object.keys(ips).length + 2}`;
  }
  ips[packet.chaddr] = ip;

  const offer = s.createOffer(packet);
  offer.yiaddr = ip;

  console.log(offer.log());
  s.send(offer);
});

s.on("request", (e) => {
  const { packet } = e;
  console.log(packet.log());

  const ack = s.createAck(packet);
  ack.yiaddr = ips[packet.chaddr];

  console.log(ack.log());
  s.send(ack);
});

s.on("release", (e) => {
  const { packet } = e;
  console.log(packet.log());
  delete ips[packet.chaddr];
});

s.bind();

RFC

For more information about DHCP, you can refer to the following RFCs:

Keywords

dhcp

FAQs

Package last updated on 24 Sep 2024

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