Created
July 7, 2022 10:19
-
-
Save Jamie0/e670db3befd28ba422983453e935c283 to your computer and use it in GitHub Desktop.
Shows the difference between `netstat -s` captures in different files, in a nice table.
This file contains 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
const fs = require('fs').promises; | |
(async function () { | |
let files = process.argv.slice(2); | |
let tableColumns = {} | |
for (var file of files) { | |
let input = String(await fs.readFile(file)) | |
let lines = input.split('\n'); | |
for (var line of lines) { | |
let match = line.match(/\b[0-9]+\b/) | |
if (match && match[0]) { | |
let column = line.replace(/\b[0-9]+\b/g, '').trim() | |
if (!tableColumns[column]) { | |
tableColumns[column] = []; | |
} | |
tableColumns[column].push(match[0].trim()) | |
} | |
} | |
} | |
tableColumns = Object.entries(tableColumns).map(([k, v]) => [k, v.map((v, i, a) => { | |
let diff = v - (a[i - 1] || 0); | |
return [v, (diff < 0 ? '-' : '+') + Math.abs(diff)]; | |
})]) | |
tableColumns.sort((a, b) => parseInt(b[1][1][1]) - parseInt(a[1][1][1])) | |
tableColumns.forEach((col) => { | |
col[1] = col[1].map((itm, ind) => ind ? itm[1] : itm[0]) //itm.join(' ')) | |
}) | |
let table = Object.fromEntries(tableColumns); | |
delete table['echo replies:']; | |
delete table['destination unreachable:']; | |
delete table['echo requests:']; | |
console.table(table) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment