Skip to content

Instantly share code, notes, and snippets.

@frnkst
Created June 19, 2018 11:37
Show Gist options
  • Save frnkst/b3427afe22df8275c04347ad8380792a to your computer and use it in GitHub Desktop.
Save frnkst/b3427afe22df8275c04347ad8380792a to your computer and use it in GitHub Desktop.
M4
function handleReply(ip, symbolicAddress) {
if (timeout) {
clearTimeout(timeout);
}
if (ip) {
const elapsedTime = `${(process.hrtime(startTime)[1] / 1000000).toFixed(3)} ms`;
if (ip === previousIP) {
process.stdout.write(` ${elapsedTime}`);
} else if (tries === 1) {
process.stdout.write(`\n ${ttl} ${symbolicAddress ? symbolicAddress : ip} (${ip}) ${elapsedTime}`);
} else {
process.stdout.write(`\n ${symbolicAddress ? symbolicAddress : ip} (${ip}) ${elapsedTime}`);
}
} else {
if (tries === 1) {
process.stdout.write(`\n ${ttl} * `);
} else {
process.stdout.write(`* `);
}
}
if ((ip == DESTINATION_IP && tries === 3) || ttl >= MAX_HOPS) {
console.log('');
process.exit();
}
previousIP = ip;
setImmediate(sendPacket);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment