ip-poll von nmap auf ping geändert
This commit is contained in:
parent
ec191271b0
commit
4a5cfe55ac
27
ip-poll.js
27
ip-poll.js
|
@ -3,23 +3,32 @@ var EventEmitter = require('events').EventEmitter;
|
||||||
var exec = require('child_process').exec;
|
var exec = require('child_process').exec;
|
||||||
|
|
||||||
|
|
||||||
var IpPoll = function(switchaddr, hostsaddr) {
|
var IpPoll = function(target) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var regexp = /\(([0-9]+) hosts* up\)/;
|
var regexp = /([0-9]+)% packet loss/m;
|
||||||
var nmap = "nmap -n -sP ";
|
var command = "LANG=C ping -c 2";
|
||||||
|
|
||||||
this.pollState = function() {
|
this.pollState = function() {
|
||||||
exec(nmap + switchaddr, function (error, stdout, stderr) {
|
try {
|
||||||
if(error == null) {
|
exec(command + " " + target, function (error, stdout, stderr) {
|
||||||
|
// console.log(stdout);
|
||||||
|
|
||||||
var matches = regexp.exec(stdout);
|
var matches = regexp.exec(stdout);
|
||||||
if(matches != null && matches.length === 2) {
|
if (matches != null) {
|
||||||
self.emit('doneState', matches[1] === "1");
|
|
||||||
|
// 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…
Reference in New Issue