Last active
December 11, 2015 04:29
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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