Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destination is never output #14

Open
leinelissen opened this issue Aug 29, 2023 · 2 comments
Open

Destination is never output #14

leinelissen opened this issue Aug 29, 2023 · 2 comments

Comments

@leinelissen
Copy link

leinelissen commented Aug 29, 2023

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);
         }
     }
 
@zulhilmizainuddin
Copy link
Owner

zulhilmizainuddin commented Sep 3, 2023

What OS are you using?

The traceroute command outputs the destination to stdout in Fedora 38 and Ubuntu 22.04.

$ traceroute google.com 2>/dev/null
traceroute to google.com (216.58.200.14), 30 hops max, 60 byte packets
 1  _gateway (192.168.0.1)  1.640 ms  2.055 ms  2.034 ms
 2  175.140.35.254 (175.140.35.254)  8.207 ms  8.772 ms  8.754 ms
 3  10.55.49.65 (10.55.49.65)  8.726 ms 10.55.49.251 (10.55.49.251)  8.712 ms 10.55.49.67 (10.55.49.67)  8.688 ms
 4  10.55.48.24 (10.55.48.24)  9.209 ms  9.191 ms 10.55.48.22 (10.55.48.22)  9.117 ms
 5  72.14.214.220 (72.14.214.220)  9.082 ms 72.14.214.196 (72.14.214.196)  16.420 ms 72.14.214.220 (72.14.214.220)  10.948 ms
 6  * * *
 7  142.250.62.58 (142.250.62.58)  11.918 ms 108.170.229.108 (108.170.229.108)  5.229 ms 142.251.255.26 (142.251.255.26)  8.419 ms
 8  kul09s16-in-f14.1e100.net (216.58.200.14)  8.361 ms 216.239.48.239 (216.239.48.239)  8.889 ms 108.170.250.13 (108.170.250.13)  8.847 ms

@leinelissen
Copy link
Author

leinelissen commented Sep 4, 2023

This is the output for that command on macOS:

➜  ~ traceroute -v google.com 2>/dev/null
 1  unifi (**REDACTED**)  0.792 ms  0.404 ms  0.589 ms
 2  **REDACTED** (**REDACTED**)  1.977 ms  1.859 ms  1.912 ms
 3  * * *
 4  hm-rc0100-cr102-be2030-201.core.as33915.net (213.51.200.45)  14.514 ms  13.798 ms  12.336 ms
 5  asd-tr0021-cr101-be111-2.core.as33915.net (213.51.7.88)  15.732 ms  14.790 ms  15.938 ms
 6  asd-tr0021-cr101-be111-2.core.as33915.net (213.51.7.88)  13.843 ms  13.955 ms  15.102 ms
 7  nl-ams14a-ri1-ae51-0.core.as9143.net (213.51.64.186)  18.283 ms  15.581 ms  17.784 ms
 8  74.125.146.228 (74.125.146.228)  15.363 ms
    10ge-1-4.cr1.ams2.baseip.com (213.46.182.22)  19.172 ms
    74.125.146.228 (74.125.146.228)  17.393 ms
 9  * * *
10  172.253.66.186 (172.253.66.186)  15.490 ms
    172.253.71.200 (172.253.71.200)  19.885 ms
    142.251.255.40 (142.251.255.40)  20.709 ms
11  108.170.241.141 (108.170.241.141)  17.424 ms
    108.170.241.173 (108.170.241.173)  15.437 ms
    142.250.224.133 (142.250.224.133)  18.923 ms
12  216.239.41.209 (216.239.41.209)  17.998 ms
    ams17s09-in-f14.1e100.net (216.58.214.14)  15.259 ms  16.048 ms

This is the version:

➜  ~ traceroute -v                     
Version 1.4a12+Darwin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants