I want use node.js to ping host in local network. Here is my code :
var ping = require('ping');
var host2 = ['192.168.0.1', '192.168.1.2', '192.168.2.3'];
host2.forEach(function(host){
ping.sys.probe(host, function(active){
var info = active ? 'IP ' + host + ' = Active' : 'IP ' + host + ' = Non-Active';
console.log(info);
});
});
This code only run (ping) once. All I want is to ping continuously. Is this possible with node.js?
EDIT : When I run the code :
EDIT 2 : When using setInterval / setTimeout :
Code :
var ping = require('ping');
var host2 = ['192.168.0.1', '192.168.1.2', '192.168.2.3'];
host2.forEach(function(host){
ping.sys.probe(host, function tes(active){
var info = active ? 'IP ' + host + ' = Active' : 'IP ' + host + ' = Non-Active';
console.log(info);
});
setInterval(tes, 2000);
});
Result :
setInterval
will do the trick – Yeah