Skip to content

Instantly share code, notes, and snippets.

@mhagrelius
Created September 26, 2019 01:53
Show Gist options
  • Save mhagrelius/5d56eb60b755a3a5a575bad9edf817b5 to your computer and use it in GitHub Desktop.
Save mhagrelius/5d56eb60b755a3a5a575bad9edf817b5 to your computer and use it in GitHub Desktop.
Basic Internet Troubleshooter
#! /usr/bin/env node
const colors = require("colors");
const ping = require("ping");
const util = require("util");
const readline = require("readline");
const speedTest = require("speedtest-net");
const addresses = {
"router": "192.168.1.1"
};
const requests = [];
const pingCfg = {
timeout: 5
};
const speedTestFn = util.promisify(speedTest.visual);
console.log("\x1Bc");
//process.stdout.write("\x1B[2J\x1B[0f");
console.log("Beginning ping tests:\n".bold.underline);
for (const key in addresses) {
requests.push(wrappedPing(key).then(msg => console.log(msg)));
}
Promise.all(requests).then(() => {
console.log("\n\nBeginning speed test\n".bold.underline);
speedTestFn({ maxTime: 10000 })
.then(() => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("\n\nPress enter to quit. ", function(answer) {
rl.close();
});
})
.catch(err => console.error(err));
});
function wrappedPing(key) {
return new Promise((resolve, reject) => {
ping.sys.probe(
addresses[key],
isAlive => {
const result = isAlive ? " ".bgGreen : " ".bgRed;
resolve(`${result} - ${key}`);
},
pingCfg
);
});
}
{
"name": "internet-troubleshooter",
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": {
"check-internet": "./index.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"colors": "^1.3.3",
"ping": "^0.2.2",
"speedtest-net": "^1.4.3"
}
}
@mhagrelius
Copy link
Author

quick and dirty node script for running some basic network tests at a client's site. Update the key/value pairs in addresses to test multiple routers/switches/endpoints in the environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment