ip-poll von nmap auf ping geändert

This commit is contained in:
Lucas Pleß 2022-09-04 15:11:02 +02:00
parent ec191271b0
commit 4a5cfe55ac
1 changed files with 20 additions and 11 deletions

View File

@ -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");
}
};
};