Skip to content

Instantly share code, notes, and snippets.

@vaxinate
Forked from bhelx/trace.js
Created January 16, 2013 09:04
Show Gist options
  • Save vaxinate/4545717 to your computer and use it in GitHub Desktop.
Save vaxinate/4545717 to your computer and use it in GitHub Desktop.
/**
* Intelligent Traceroute
*
* Do a traceroute on a domain, prints a json array
* of the hops with their physical locations.
*
* //Example
* node trace.js google.com
*
* npm install traceroute async underscore request
*/
var traceroute = require('traceroute')
, async = require('async')
, _ = require('underscore')
, request = require('request')
, util = require('util')
;
function geoip (ip, done) {
request.get({
url: "http://freegeoip.net/json/"+ip,
json: true
}, function (err, res, body) {
body.ip = ip;
done(err, body);
});
}
traceroute.trace(process.argv[2], function (err, hops) {
if (err) throw err;
var ips = _.map(hops, function (hop) {
return _.first(Object.keys(hop))
});
async.map(ips, geoip, function (err, results) {
console.log(results);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment