ip-poll von nmap auf ping geändert

citesting
Lucas Pleß 3 weeks ago
parent ec191271b0
commit 4a5cfe55ac
  1. 31
      ip-poll.js

@ -3,23 +3,32 @@ var EventEmitter = require('events').EventEmitter;
var exec = require('child_process').exec;
var IpPoll = function(switchaddr, hostsaddr) {
var IpPoll = function(target) {
var self = this;
var regexp = /\(([0-9]+) hosts* up\)/;
var nmap = "nmap -n -sP ";
var regexp = /([0-9]+)% packet loss/m;
var command = "LANG=C ping -c 2";
this.pollState = function() {
exec(nmap + switchaddr, function (error, stdout, stderr) {
if(error == null) {
try {
exec(command + " " + target, function (error, stdout, stderr) {
// console.log(stdout);
var matches = regexp.exec(stdout);
if(matches != null && matches.length === 2) {
self.emit('doneState', matches[1] === "1");
if (matches != null) {
// console.log("matches " + JSON.stringify(matches));
// console.log("length: " + matches.length);
// console.log("matches 1: " + matches[1]);
if (matches.length === 2) {
self.emit('doneState', matches[1] === "0");
}
}
} else {
self.emit('doneState', "unknown");
}
});
});
} catch(err) {
self.emit('doneState', "unknown");
}
};
};

Loading…
Cancel
Save