Created
July 23, 2012 09:38
-
-
Save tiff/3162821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"), | |
exec = require("child_process").exec, | |
macAddresses = { | |
"00:25:00:48:26:b3": { | |
name: "Christopher", | |
times: 0, | |
log: 0 | |
}, | |
"74:e5:0b:a6:6f:94": { | |
name: "Wolfgang", | |
times: 0, | |
log: 0 | |
}, | |
"00:26:bb:09:62:7d": { | |
name: "Ali", | |
times: 0, | |
log: 0 | |
}, | |
"74:e5:0b:ca:96:28": { | |
name: "Daniel", | |
times: 0, | |
log: 0 | |
} | |
}; | |
function log() { | |
exec("iw wlan0 station dump", function(err, output) { | |
for (var macAddress in macAddresses) { | |
var match = output.match(new RegExp(macAddress + "[\\s\\S]+?signal:.+?-(\\d+)", "i")); | |
if (match) { | |
macAddresses[macAddress].log += Number(match[1]); | |
macAddresses[macAddress].times += 1; | |
} | |
} | |
renderResults(); | |
}); | |
} | |
function renderResults() { | |
output = ""; | |
for (var macAddress in macAddresses) { | |
if (macAddresses[macAddress].times) { | |
var average = macAddresses[macAddress].log / macAddresses[macAddress].times; | |
output += macAddresses[macAddress].name + ": -" + average + " dBm (" + macAddresses[macAddress].times + " logs)\n"; | |
} | |
} | |
fs.writeFile('dbm.log', output, function (err) {}); | |
} | |
log(); | |
setInterval(log, 1000 * 60 * 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment