Skip to content

Instantly share code, notes, and snippets.

@bhelx
Last active December 11, 2015 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bhelx/4545588 to your computer and use it in GitHub Desktop.
Save bhelx/4545588 to your computer and use it in GitHub Desktop.
This is an incomplete thought. Doesn't actually show enough information to do anything useful.
/**
* 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