-
-
Save aredridel/8797630 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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; | |
This file contains hidden or 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 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