Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

var Trace = require('..')
var chalk = require('chalk')
const url = require('url');
const dns = require('dns-sync');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dns-sync isn't a core module – looks like you forgot to add this to the package.json.

Also, the dns-sync module spawns a new node process through shelljs for each resolve – I'm not sure how desirable that is, compared to just using the core's dns module and deal with the asynchrony.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this a moment longer, there's no need to this at all, as the remote address is available through the response socket, so all that's needed would be the following:

diff --git a/bin/cli.js b/bin/cli.js
index d71a9c2..bb431ad 100755
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -19,6 +19,7 @@ var trace = new Trace(process.argv[2])
       chalk.yellow(step.protocol + '/' + step.protocolVersionMajor + '.' + step.protocolVersionMinor),
       chalk.gray(step.method),
       step.url,
+      chalk.red(step.remoteAddress),
       chalk.gray(step.newCookies ? '(cookies: ' + step.newCookies + ') ' : '') +
       chalk.cyan('(' + step.time + ' ms)')
     )
diff --git a/lib/trace.js b/lib/trace.js
index a7b1a6a..8d33edf 100755
--- a/lib/trace.js
+++ b/lib/trace.js
@@ -131,6 +131,7 @@ Object.assign(Trace.prototype, {
       self.statusCode = res.statusCode

       self.push({
+        remoteAddress: res.socket.remoteAddress,
         protocol: res.protocol,
         protocolVersionMajor: res.httpVersionMajor,
         protocolVersionMinor: res.httpVersionMinor,


var trace = new Trace(process.argv[2])
.once('error', function (error) {
Expand All @@ -14,11 +16,14 @@ var trace = new Trace(process.argv[2])
console.log('Trace finished in %s using %s', chalk.cyan(trace.time + ' ms'), chalk.cyan(trace.hops + ' hop' + (trace.hops > 1 ? 's' : '')))
})
.on('data', function (step) {
const u = url.parse(step.url)
const ip = dns.resolve(u.hostname)
console.log(
chalk.green('[' + step.statusCode + ']'),
chalk.yellow(step.protocol + '/' + step.protocolVersionMajor + '.' + step.protocolVersionMinor),
chalk.gray(step.method),
step.url,
chalk.red(ip),
chalk.gray(step.newCookies ? '(cookies: ' + step.newCookies + ') ' : '') +
chalk.cyan('(' + step.time + ' ms)')
)
Expand Down