Giter Club home page Giter Club logo

node-traceroute's Introduction

node-traceroute

Simple wrapper around native traceroute command. Each hop contains the hosts in that hop and the respective round trip times of each host.

Install

$ npm install traceroute

Usage

The trace method will always return a steam and will call an optional callback when done.

Stream

const Traceroute = require('traceroute');

const trace = Traceroute.trace('google.com');

trace.on('hop', (hop) => {

    console.log(hop)
});

trace.on('done', (hops) => {

    console.log(hops);
});

Async

const Traceroute = require('traceroute');

Traceroute.trace('google.com', (err, hops) => {

    if (err) {
        throw err;
    }

    console.log(hops);
});

This example would write the following to the console if run from my network...

[ { '66.97.5.249': [ 43.206, 43.377, 43.379 ] },
  { '216.182.7.102': [ 43.575, 43.799, 43.808 ] },
  { '216.182.7.165': [ 44.538, 44.613, 44.837 ] },
  { '216.182.7.253': [ 44.846, 56.281, 56.303 ] },
  { '4.53.88.197': [ 57.735, 57.707, 57.891 ] },
  { '4.69.155.254': [ 58.618, 48.514, 48.567 ] },
  { '4.69.134.77': [ 34.167, 44.317 ], '4.69.148.45': [ 44.366 ] },
  { '4.69.141.22': [ 44.542, 44.316, 44.642 ] },
  { '4.69.138.196': [ 44.56, 35.554 ],
    '4.69.138.228': [ 45.035 ] },
  { '4.59.128.18': [ 35.777, 35.827, 45.305 ] },
  { '72.14.238.232': [ 45.621 ],
    '209.85.255.68': [ 45.079, 42.695 ] },
  { '209.85.251.37': [ 32.588, 32.569, 32.657 ] },
  { '209.85.251.9': [ 59.068 ],
    '209.85.254.48': [ 60.287, 75.094 ] },
  { '66.249.94.22': [ 61.565, 62.063 ],
    '72.14.238.242': [ 63.001 ] },
  { '64.233.174.140': [ 96.476, 97.585 ],
    '72.14.239.83': [ 98.656 ] },
  { '64.233.174.191': [ 149.286, 93.528, 94.405 ] },
  { '216.239.43.76': [ 83.901, 85.089, 84.837 ] },
  { '74.125.224.240': [ 84.645, 75.322, 75.585 ] } ]

node-traceroute's People

Contributors

jaw187 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-traceroute's Issues

i is not defined

When running sample snippet to trace route www.google.com

traceroute = require('traceroute');
traceroute.trace('google.com', function (err,hops) {
  if (!err) console.log(hops);
});

Getting this error.

\node_modules\traceroute\traceroute.js:114
        lines.splice(0,i);
                       ^

ReferenceError: i is not defined
    at Object.internals.parseOutput (..\node_modules\traceroute\traceroute.js:114:24)
    at ..\node_modules\traceroute\traceroute.js:35:39
    at ChildProcess.exithandler (child_process.js:299:7)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:467:12)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)

Error on windows (variable scope)

I just tried to use your wrapper and got an error (solved it by myself, just for you to correct)
See this code:

    if (internals.isWin) {
        for (let i = 0; i < lines.length; ++i) {
            if (/^\s+1/.test(lines[i])) {
                break;
            }
        }
        lines.splice(0,i);
        lines.pop();
        lines.pop();
    }

"let i" scope is only in the for loop and cant be accessed in lines.splice. Exchange let with var solves the problem
Maybe lines.length instead of i would do it too i think

License?

Hi there

What license applies to this repository? The package json mentions ISC but the repository should specify the license formally.

This is the only thing holding us back from using the repository.

Thanks

Daniel

undefined function dns.lookup

Hi, i was trying to run the exact code from the example, tracing google.com
However, i've got an error "undefined is not a function" in the line of "dns.lookup(host, function (err) {" inside the module.

Do i need to setup something for the dns lookup?

Allow ICMP ECHO traceroute

Hello,

Would you be receptive to a pull request that made traceroute use ICMP ECHO on Unix platforms as well?

This is the default behavior on Windows, and it would be great if we could use -I on Unix to achieve similar functionality. Makes it easier to work with hosts that are firewalled but allow pings.

Update NPM

You need to update npm to the newest version in this repo. Otherwise you get

trace.on('hop', (hop) => {
^

TypeError: Cannot read property 'on' of undefined
at Object. (/Users/developmentmastery/Repos/testing-traceroute/index.js:5:6)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:445:3

When you try to use stream.

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.