this should do:
tracerute = require('traceroute');
traceroute.trace('4.69.155.254', function (err,hops) {
if (err) console.error(err)
else hops.forEach(function(hop, index){
console.log(index + 1, hop)
});
});
if you whant to transform your data and save the transformed result:
tracerute = require('traceroute');
traceroute.trace('4.69.155.254', function (err,hops) {
if (err) console.error(err)
else {
hops = hops.forEach(function(hop, index){
hop.lineno = index +1
});
}
});
regarding the db: for storing this kind of data all dbs would fit. it
depends more on your other requirements like performance, scalability, SQL
or not, realtional algebra or map/reducing, reliability, persistence and so
on.
Am Dienstag, 13. August 2013 12:47:19 UTC+2 schrieb Mattias Larsson:
>
> Hi,
>
> How should I think (and do) to add numbers to each hop (line) on my
> traceroute.
>
> Here is my script (it's example script from traceroute npm package)
>
> traceroute = require('traceroute');
> traceroute.trace('4.69.155.254', function (err,hops) {
> if (!err) console.log(hops);});
>
>
> And output is like this
>
> [ { '66.97.5.249': [ 43.206 ] },
> { '216.182.7.102': [ 43.575 ] },
> { '216.182.7.165': [ 44.538 ] },
> { '216.182.7.253': [ 44.846 ] },
> { '4.53.88.197': [ 57.735 ] },
> { '4.69.155.254': [ 58.618 ] } ]
>
>
> I would like to change how data is showing, with adding an line number.
> like this.
>
> [ { '1', '66.97.5.249': [ 43.206 ] },
> { '2', '216.182.7.102': [ 43.575 ] },
> { '3', '216.182.7.165': [ 44.538 ] },
> { '4', '216.182.7.253': [ 44.846 ] },
> { '5', '4.53.88.197': [ 57.735 ] },
> { '6', '4.69.155.254': [ 58.618 ] } ]
>
> I think I need to calculate how many hops it is, and then do a for loop to
> add the number to each line?!
>
>
> I'm also going to add this output data into a database. I don't know which
> database to use. I appreciate if someone can recommend some database I
> should use. MongoDB, Redis, Sqlite?
>
>
> Regards,
> Mattias
>
>
>
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.