0.1.0 • Published 11 years ago
traceroute-lite v0.1.0
traceroute-lite 
A simple traceroute module for NodeJS apps.
Install
npm install traceroute-lite-or-
npm install ben-bradley/traceroute-liteTest
npm test-or-
mocha -R specUsage
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). Thedoneevent occurs before the callback is executed.
Methods
Traceroute.start(callback)accepts an optional callback that returns(error, hops). Thedoneevent 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();0.1.0
11 years ago