#NODE-PING
a ping wrapper for nodejs
@last-modified: 2016-10-21 12:43
#LICENSE MIT
(C) Daniel Zelisko
http://github.com/danielzzz/node-ping
#DESCRIPTION
node-ping is a simple wrapper for the system ping utility
#INSTALLATION
npm install ping
#USAGE
Below are examples extracted from examples
##Tradition calls
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);
});
});
##Tradition calls with configuration
var cfg = {
timeout: 10,
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);
});
##Promise wrapper
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);
});
});
##Promise Wrapper with configable ping options
hosts.forEach(function (host) {
ping.promise.probe(host, {
timeout: 10,
extra: ["-i 2"],
}).then(function (res) {
console.log(res);
});
});
Support configuration
Below is the possible configuration
Output specification
- For callback based implementaiton:
- For promise based implementation
Note
-
Since ping in this module relies on the ping from underlying platform,
arguments in PingConfig.extra will definitely be varied across different
platforms.
-
However, numeric, timeout and min_reply have been abstracted. Values for
them are expected to be cross platform.
-
By setting numeric, timeout or min_reply to false, you can run ping
without corresponding arguments.
Contributing
Before opening a pull request please make sure your changes follow the
contribution guidelines.