raumstatus/node/test.js

51 lines
1.2 KiB
JavaScript
Raw Normal View History

var moment = require("moment");
2013-11-26 12:59:34 +00:00
var snmp = require("net-snmp");
2013-11-26 12:59:34 +00:00
var baseoid = "1.3.6.1.2.1.17.7.1.2.2.1.3";
var regexp = /([0-9]+).([0-9]+).([0-9]+).([0-9]+).([0-9]+).([0-9]+)$/;
2013-11-26 12:59:34 +00:00
var session = snmp.createSession("juni.ctdo.de", "ctdo23", { version: snmp.Version2c } )
2013-11-26 12:59:34 +00:00
function getMacFromOID(oid, callback) {
var matches = regexp.exec(oid);
var mac = "";
2013-11-26 12:59:34 +00:00
if(matches != null) {
for(var i = 1; i < matches.length; i++) {
var num = parseInt(matches[i]);
if(num <= 15) mac += "0";
mac += num.toString(16) + ":";
}
mac = mac.substr(0, mac.length-1);
2013-11-26 12:59:34 +00:00
callback(mac);
}
}
2013-11-26 12:59:34 +00:00
function doneCb(error) {
if (error)
console.error(error.toString ());
2013-11-26 12:59:34 +00:00
}
2013-11-26 12:59:34 +00:00
function feedCb(varbinds) {
for (var i = 0; i < varbinds.length; i++) {
if (snmp.isVarbindError(varbinds[i])) {
console.error(snmp.varbindError (varbinds[i]));
} else {
if(varbinds[i].value == "3") { // only valid arp entries
getMacFromOID(varbinds[i].oid, function(mac) {
console.log(mac);
2013-11-26 12:59:34 +00:00
});
}
}
}
}
2013-11-26 12:59:34 +00:00
session.subtree(baseoid, 20, feedCb, doneCb);