traceroute-node

A traceroute implementation for Node.js


Keywords
traceroute, trace route, mtr, hops, raw-sockets, dgram
License
MIT
Install
npm install traceroute-node@1.1.0

Documentation

traceroute-node

A traceroute implementation for Node.js using dgram and raw sockets.

How to use it

Installation

npm i traceroute-node

Example usage with JavaScript:

const { Traceroute } = require('traceroute-node');

new Traceroute("8.8.8.8")
  .onHop((hop) => console.log(hop))
  .onDone(() => console.log("done"));
  • onHop callback gets executed everytime a new hop is reached
  • onDone callback gets executes when traceroute is done

A hop contains the ip address, and the milliseconds it took:

[{ ip: '8.8.8.8', ms: 23 },
{ ip: '8.8.8.8', ms: 23 },
{ ip: '8.8.8.8', ms: 23 }]

Example usage with TypeScript:

import { Traceroute, Hop } from "traceroute-node";

new Traceroute("8.8.8.8")
.onHop((hop: Hop[]) => console.log(hop))
.onDone(() => console.log("done"));

Example with custom options:

new Traceroute("8.8.8.8", {
  probes: 2,
  maximumHops: 3,
  reverseLookup: true,
  timeoutInMillis: 3000,
})
  .onHop((hop: Hop[]) => console.log(hop))
  .onDone(() => console.log("done"));

All options are optional. The defaults are:

const defaultOptions: Options = {
  probes: 3,
  maximumHops: 64,
  timeoutInMillis: 3000,
  reverseLookup: false,
};