Coder Social home page Coder Social logo

nodejs-traceroute's People

Contributors

dependabot[bot] avatar ericulevik avatar zulhilmizainuddin 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nodejs-traceroute's Issues

Destination is never output

Hey there! Thanks for all the work in making this package. I truly appreciate it.

When using this package, I found out that the destination is never properly returned. I figured out that this is because the header that includes the destination is output in stderr rather than stdout. In order to fix this, I've applied this patch in my local repository using patch-package.

diff --git a/node_modules/nodejs-traceroute/lib/process.js b/node_modules/nodejs-traceroute/lib/process.js
index 0fea080..c169df8 100644
--- a/node_modules/nodejs-traceroute/lib/process.js
+++ b/node_modules/nodejs-traceroute/lib/process.js
@@ -25,24 +25,28 @@ class Process extends events_1.default.EventEmitter {
         });
         this.emit('pid', process.pid);
         let isDestinationCaptured = false;
+        const parseLine = (line) => {
+            if (!isDestinationCaptured) {
+                const destination = this.parseDestination(line);
+                if (destination !== null) {
+                    this.emit('destination', destination);
+                    isDestinationCaptured = true;
+                }
+            }
+            const hop = this.parseHop(line);
+            if (hop !== null) {
+                this.emit('hop', hop);
+            }
+        };
         if (process.pid) {
             readline_1.default.createInterface({
                 input: process.stdout,
                 terminal: false
-            })
-                .on('line', (line) => {
-                if (!isDestinationCaptured) {
-                    const destination = this.parseDestination(line);
-                    if (destination !== null) {
-                        this.emit('destination', destination);
-                        isDestinationCaptured = true;
-                    }
-                }
-                const hop = this.parseHop(line);
-                if (hop !== null) {
-                    this.emit('hop', hop);
-                }
-            });
+            }).on('line', parseLine);
+            readline_1.default.createInterface({
+                input: process.stderr,
+                terminal: false
+            }).on('line', parseLine);
         }
     }
     isValidDomainName(domainName) {
diff --git a/node_modules/nodejs-traceroute/src/process.ts b/node_modules/nodejs-traceroute/src/process.ts
index 9843c83..d494ca5 100644
--- a/node_modules/nodejs-traceroute/src/process.ts
+++ b/node_modules/nodejs-traceroute/src/process.ts
@@ -32,26 +32,32 @@ export abstract class Process extends events.EventEmitter {
         this.emit('pid', process.pid);
 
         let isDestinationCaptured = false;
+
+        const parseLine = (line: string) => {
+            if (!isDestinationCaptured) {
+                const destination = this.parseDestination(line);
+                if (destination !== null) {
+                    this.emit('destination', destination);
+
+                    isDestinationCaptured = true;
+                }
+            }
+
+            const hop = this.parseHop(line);
+            if (hop !== null) {
+                this.emit('hop', hop);
+            }
+        }
+
         if (process.pid) {
             readline.createInterface({
                     input: process.stdout,
                     terminal: false
-                })
-                .on('line', (line) => {
-                    if (!isDestinationCaptured) {
-                        const destination = this.parseDestination(line);
-                        if (destination !== null) {
-                            this.emit('destination', destination);
-
-                            isDestinationCaptured = true;
-                        }
-                    }
-
-                    const hop = this.parseHop(line);
-                    if (hop !== null) {
-                        this.emit('hop', hop);
-                    }
-                });
+            }).on('line', parseLine);
+            readline.createInterface({
+                input: process.stderr,
+                terminal: false
+            }).on('line', parseLine);
         }
     }
 

Replace "validator" lib to reduce node_modules size

Pretty self-explanatory. I'm sure that "validator" is a good lib, but it is 0.3mb in size. This is way too much for two functions in one file.

My offer is:

If repo owner allows this, I can create a pull request.

Mentioned file is https://github.com/zulhilmizainuddin/nodejs-traceroute/blob/d06023a358434d4db3ceb23a5947c149023b8dd7/process.js

on.destination is not triggered

I have this:

const Traceroute = require('nodejs-traceroute');

try {
    const tracer = new Traceroute();
    tracer
        .on('pid', (pid) => {
            console.log(`pid: ${pid}`);
        })
        .on('destination', (destination) => {
            console.log(`destination: ${destination}`);
        })
        .on('hop', (hop) => {
            console.log(`hop: ${JSON.stringify(hop)}`);
        })
        .on('close', (code) => {
            console.log(`close: code ${code}`);
        });

    tracer.trace('www.google.com');
} catch (ex) {
    console.log(ex);
}

My output:

pid: 29895
hop: {"hop":1,"ip":"192.168.1.254","rtt1":"4.481 ms"}
hop: {"hop":2,"ip":"*","rtt1":"*"}
hop: {"hop":3,"ip":"*","rtt1":"*"}
hop: {"hop":4,"ip":"31.55.185.184","rtt1":"29.203 ms"}
hop: {"hop":5,"ip":"195.99.127.146","rtt1":"32.910 ms"}
hop: {"hop":6,"ip":"109.159.252.158","rtt1":"63.543 ms"}
hop: {"hop":7,"ip":"109.159.253.69","rtt1":"31.889 ms"}
hop: {"hop":8,"ip":"*","rtt1":"*"}
hop: {"hop":9,"ip":"172.253.71.200","rtt1":"28.291 ms"}
hop: {"hop":10,"ip":"108.170.246.144","rtt1":"26.056 ms"}
hop: {"hop":11,"ip":"172.217.169.36","rtt1":"30.695 ms"}
close: code 0

there is no destination logged to the console. What is wrong?

Suggestion: Error handling - check and say that traceroute is not installed

Suggestion to add explicit error message if the environment doesn't have traceroute installed.
Currently, the system fails with a more generic error message:

"spawn traceroute ENOENT"

image

I would appreciate a nicer message, perhaps letting you know you should install the traceroute.

Of course, this should be obvious, but still, one can forget to install it in a docker image. In such cases, knowing right away what the problem is without putting in effort would save some time and nerves.

Steps to reproduce:

Run the example code without traceroute installed on your machine.

Support for ipv4 only

Hi @zulhilmizainuddin,

Really nice work, thanks. Both Traceroute and Tracert use either ipv4 or ipv6 like said here in the docs:

By default, the program will try to resolve the name given, and choose the appropriate 
protocol automatically

I would really love to have the option to force the usage of ipv4 when I need to.
What do you think?

Timeout or Hops max

Hey guys, just wandering if it is possible to add a parameter on .trace function, to provide a ttl_max.

How to stop the traceroute task?

How to stop the traceroute task?

In the usage example, how to stop the traceroute task?

const Traceroute = require('nodejs-traceroute');

try {
    const tracer = new Traceroute();
    tracer
        .on('pid', (pid) => {
            console.log(`pid: ${pid}`);
        })
        .on('destination', (destination) => {
            console.log(`destination: ${destination}`);
        })
        .on('hop', (hop) => {
            console.log(`hop: ${JSON.stringify(hop)}`);
        })
        .on('close', (code) => {
            console.log(`close: code ${code}`);
        });

    tracer.trace('github.com');

} catch (ex) {
    console.log(ex);
}

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.