raumstatus/ip-poll.js

29 lines
767 B
JavaScript
Raw Normal View History

2013-10-02 12:04:01 +00:00
var util = require('util');
var EventEmitter = require('events').EventEmitter;
2013-10-20 22:04:58 +00:00
var exec = require('child_process').exec;
2016-01-08 16:47:28 +00:00
2013-10-20 22:04:58 +00:00
2013-10-02 12:04:01 +00:00
var IpPoll = function(switchaddr, hostsaddr) {
var self = this;
2013-10-02 12:04:01 +00:00
var regexp = /\(([0-9]+) hosts* up\)/;
var nmap = "nmap -n -sP ";
2013-10-20 22:04:58 +00:00
this.pollState = function() {
exec(nmap + switchaddr, function (error, stdout, stderr) {
if(error == null) {
var matches = regexp.exec(stdout);
2022-09-04 12:18:40 +00:00
if(matches != null && matches.length === 2) {
self.emit('doneState', matches[1] === "1");
}
} else {
self.emit('doneState', "unknown");
}
});
};
2013-10-20 22:04:58 +00:00
};
2013-10-02 12:04:01 +00:00
util.inherits(IpPoll, EventEmitter);
module.exports = IpPoll;