From 70779ce69145b814f8321ef8080889b95fbda630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Tue, 26 Nov 2013 13:59:34 +0100 Subject: [PATCH] removed mac addresses from code --- node/bla | 34 +++++++++++++++++++++++++++++ node/snmp-mac.js | 11 ++-------- node/test.js | 56 ++++++++++++++++++++++++++++++++---------------- 3 files changed, 74 insertions(+), 27 deletions(-) create mode 100644 node/bla diff --git a/node/bla b/node/bla new file mode 100644 index 0000000..8f6842e --- /dev/null +++ b/node/bla @@ -0,0 +1,34 @@ +member: cn=tidirium,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=tatonka,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=ulihd,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=nospoonuser,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=progamler,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=zeus,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=lichtscheu,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=stefan,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=wegginho,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=jcoder,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=smash,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=pascal,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=herbern,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=syn,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=seppo,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=blueberry,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=immo,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=freakfairy,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=badboy,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=alteisen,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=eimann,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=downhill,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=annett,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=dukat,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=klapauzius,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=hotte,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=henne,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=tunix,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=fiurin,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=jsilence,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=kuro,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=klara,ou=people,dc=chaostreff-dortmund,dc=de +member: cn=lucas,ou=people,dc=chaostreff-dortmund,dc=de + diff --git a/node/snmp-mac.js b/node/snmp-mac.js index dba1c00..d6c9ff5 100644 --- a/node/snmp-mac.js +++ b/node/snmp-mac.js @@ -18,15 +18,8 @@ var SnmpMac = function(hostname, community) { var names = []; redisClient.on("connect", function () { - redisClient.set(redisprefix + "24:77:03:a9:f3:f4","lucas"); - redisClient.set(redisprefix + "3c:97:0e:22:b7:68","lucas"); - redisClient.set(redisprefix + "a0:0b:ba:c7:98:e5","lucas"); - redisClient.set(redisprefix + "b8:27:eb:7d:6f:d2","rpi2"); - redisClient.set(redisprefix + "b8:27:eb:7b:9b:9a","rpi3"); - redisClient.set(redisprefix + "a8:88:08:10:a0:c5","pascal"); - redisClient.set(redisprefix + "c8:97:9f:72:8f:67","fisch"); - redisClient.set(redisprefix + "00:80:a3:91:39:1c","ripe-atlas-probe"); - redisClient.set(redisprefix + "d4:ca:6d:33:cf:79","routerboard"); + //redisClient.set(redisprefix + "00:80:a3:91:39:1c","ripe-atlas-probe"); + //redisClient.set(redisprefix + "d4:ca:6d:33:cf:79","routerboard"); console.log("connected to redis"); self.emit('ready'); diff --git a/node/test.js b/node/test.js index 2cc8cfd..201bc02 100644 --- a/node/test.js +++ b/node/test.js @@ -1,30 +1,50 @@ var moment = require("moment"); -var redis = require("redis"); -var redisClient = redis.createClient(); - -redisClient.on("connect", function () { - console.log("connected to redis"); +var snmp = require("net-snmp"); +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]+)$/; + +var session = snmp.createSession("juni.ctdo.de", "ctdo23", { version: snmp.Version2c } ) +function getMacFromOID(oid, callback) { + var matches = regexp.exec(oid); + var mac = ""; - redisClient.zrangebyscore('onlinecount', "-inf", "+inf", function(err, replies) { + 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); - var data = []; + callback(mac); + } +} - replies.forEach(function (reply, i) { +function doneCb(error) { + if (error) + console.error(error.toString ()); - var line = reply.split('|'); - data.push( { at: moment(parseInt(line[0])).format(), value: line[1] }); +} + +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); + + }); + } + } + } +} - }); +session.subtree(baseoid, 20, feedCb, doneCb); - console.log(data); - - redisClient.quit(); - }); - - -}); \ No newline at end of file