Just another ping wrapper for nodejs.
Actually, pinguin is a fork of node-ping. It's awesome, but maintenance of this package leaves much to be desired. Usually, they merge PRs very rarely. Moreover, this package doesn't support NodeJS standard events mechanism. For now, pinguin
is fully equaled the source package.
npm install pinguin
Below are examples extracted from examples
var ping = require('ping');
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
hosts.forEach(function(host){
ping.sys.probe(host, function(isAlive){
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
console.log(msg);
});
});
var cfg = {
timeout: 10,
// WARNING: -i 2 may not work in other platform like window
extra: ['-i', '2'],
};
hosts.forEach(function(host){
ping.sys.probe(host, function(isAlive){
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
console.log(msg);
}, cfg);
});
var ping = require('ping');
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
hosts.forEach(function (host) {
ping.promise.probe(host)
.then(function (res) {
console.log(res);
});
});
hosts.forEach(function (host) {
// WARNING: -i 2 argument may not work in other platform like window
ping.promise.probe(host, {
timeout: 10,
extra: ['-i', '2'],
}).then(function (res) {
console.log(res);
});
});
Below is the possible configuration
/**
* Cross platform config representation
* @typedef {Object} PingConfig
* @property {boolean} numeric - Map IP address to hostname or not
* @property {number} timeout - Time duration for ping command to exit
* @property {number} min_reply - Exit after sending number of ECHO_REQUEST
* @property {string[]} extra - Optional options does not provided
*/
- For callback based implementaiton:
/**
* Callback after probing given host
* @callback probeCallback
* @param {boolean} isAlive - Whether target is alive or not
* @param {Object} error - Null if no error occurs
*/
- For promise based implementation
/**
* Parsed response
* @typedef {object} PingResponse
* @param {string} host - The input IP address or HOST
* @param {string} numeric_host - Target IP address
* @param {boolean} alive - True for existed host
* @param {string} output - Raw stdout from system ping
* @param {number} time - Time (float) in ms for first successful ping response
* @param {Array} times - Array of Time (float) in ms for each ping response
* @param {string} min - Minimum time for collection records
* @param {string} max - Maximum time for collection records
* @param {string} avg - Average time for collection records
* @param {string} stddev - Standard deviation time for collected records
*/