Skip to content

Instantly share code, notes, and snippets.

@aredridel
Forked from anonymous/file1.js
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aredridel/8797630 to your computer and use it in GitHub Desktop.
Save aredridel/8797630 to your computer and use it in GitHub Desktop.
var exec = require('child_process').exec;
function wew(cb){
exec("iwlist wlan2 scan|grep -Po '(?<=Address: )\\S+|(?<=Signal level=)\\S+|(?<=ESSID:\")[^\"]+'", test(cb));
}
function test(cb) {
return function (error, stdout, stderr) {
var out = stdout.replace(/^\s+/mg, '');
out = out.split('\n');
var cells = [];
var line;
var info = {};
for (var i=0,l=out.length-1,m=1; i<l; i++,m++) {
line = out[i];
if(i%3 == 0 && i!=0){
cells.push(info);
info = {};
}
if(m%3==1) { info['mac'] = line; }
else if(m%3==2) { info['signal'] = line; }
else if(m%3==0) { info['essid'] = line; }
}
cells.push(info);
// console.log(cells);
for (var i in cells) {
// console.log("the array: " + cells[i].mac); //"aa", bb", "cc"
}
cb(cells);
}
}
exports.command = wew;
var reader = require( './file1.js' );
reader.command(function (bang) {
console.log(bang);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment