Git Product home page Git Product logo

traceroute-lite's Introduction

traceroute-lite NPM

A simple traceroute module for NodeJS apps.

Install

npm install traceroute-lite

-or-

npm install ben-bradley/traceroute-lite

Test

npm test

-or-

mocha -R spec

Usage

var Traceroute = require('traceroute-lite');

var traceroute = new Traceroute('8.8.8.8');

traceroute.on('hop', function(hop) {
  console.log(hop); // { counter: 1, ip: '1.2.3.4', ms: 12 }
});

traceroute.start(function(err, hops) {
  console.log(hops);
  /* [
   *  { counter: 1, ip: '1.2.3.4', ms: 12 },
   *  { counter: 2, ip: '1.2.3.5', ms: 34 },
   *  ...,
   *  { counter: n, ip: '8.8.8.8', ms: 10 }
   * ]
   */
});

Hop

A 'hop' is a unique IP that your trace crosses. They are represented as objects using this schema:

{
  counter: Number, // A number representing which hop this is in sequence.
  ip: String, // The IP address of the interface on the remote device.
  ms: Number, // The milliseconds it takes to reach that IP
}

If a hop fails to respond, the ip and ms are null.

Events

  • hop = When an individual hop is detected, responds with ({ counter: 1, ip: '1.2.3.4', ms: 12 }).
  • done = When the trace is complete, responds with (error, hops). The done event occurs before the callback is executed.

Methods

  • Traceroute.start(callback) accepts an optional callback that returns (error, hops). The done event occurs before the callback is executed.

Examples

Using a callback:

var Traceroute = require('traceroute-lite');

var traceroute = new Traceroute('8.8.8.8');

traceroute.start(function(err, hops) {
  console.log(hops);
  /* [
   *  { counter: 1, ip: '1.2.3.4', ms: 12 },
   *  { counter: 2, ip: '1.2.3.5', ms: 34 },
   *  ...,
   *  { counter: n, ip: '8.8.8.8', ms: 10 }
   * ]
   */
});

Using Events:

var Traceroute = require('traceroute-lite');

var traceroute = new Traceroute('8.8.8.8');

traceroute.on('hop', function(hop) {
  console.log(hop); // { counter: 1, ip: '1.2.3.4', ms: 12 }
});

traceroute.on('done', function(err, hops) {
  console.log(hops);
  /* [
   *  { counter: 1, ip: '1.2.3.4', ms: 12 },
   *  { counter: 2, ip: '1.2.3.5', ms: 34 },
   *  ...,
   *  { counter: n, ip: '8.8.8.8', ms: 10 }
   * ]
   */
});

traceroute.start();

traceroute-lite's People

Contributors

rodcul avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.