Created
January 26, 2017 13:44
-
-
Save HugoPoi/b035e1efd090ae1e5c2b3ff847ef921b to your computer and use it in GitHub Desktop.
Use iwconfig and extract signal and link quality to csv (nodejs)
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 exec = require('child_process').exec; | |
var argv = require('minimist')(process.argv.slice(2)); | |
var stringify = require('csv-stringify'); | |
var fs = require('fs'); | |
function takeMesure(callback){ | |
exec('iwconfig wlan0', function(err, stdout, stderr){ | |
//console.log(stdout); | |
var essid = /ESSID:"(.+)"/.exec(stdout), | |
power = /Bit Rate=([0-9]+) +Mb\/s +Tx\-Power=([0-9]+) dBm/.exec(stdout), | |
power_management = /Power Management:(.+)\n/.exec(stdout), | |
quality = /Link Quality=([0-9]+)\/([0-9]+) +Signal level=(\-?[0-9]+) dBm/.exec(stdout); | |
callback(err, { | |
essid: essid[1], | |
bit_rate : power[1], | |
txpower: power[2], | |
power_management: power_management[1], | |
link_quality: quality[1], | |
max_link_quality: quality[2], | |
signal_level: quality[3] | |
}); | |
}); | |
}; | |
function do_and_save(spotname){ | |
takeMesure(function(err, mesure){ | |
mesure.spotname = spotname; | |
stringify([mesure], function(err, csvdata){ | |
fs.writeFileSync('./wifi_mesures.csv', csvdata, { flag: 'a' }); | |
}); | |
}); | |
}; | |
if(argv.init){ | |
stringify([['essid', | |
'bit_rate', | |
'txpower', | |
'power_management', | |
'link_quality', | |
'max_link_quality', | |
'signal_level', 'spotname']], function(err, csvdata){ | |
fs.writeFileSync('./wifi_mesures.csv', csvdata, { flag: 'a' }); | |
}); | |
}else{ | |
do_and_save(argv.n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment