Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Absolutely necessary even to set interface to null
wifi.init({
iface : null // network interface, choose a random wifi interface if set to null
});
data = {samples: []}
if (process.argv.length <= 2) {
n = 1
} else {
n = process.argv[2]
}
for (var i=0; i < n; i++){
// Scan networks
wifi.scan(function(err, networks) {
if (err) {
console.log(err);
} else {
sample = []
networks.forEach(function(network) {
sample.push({mac: network['mac'], signal_level: network['signal_level'], ssid: network['ssid']})
})
data['samples'].push(sample)
}
});
await sleep(5000);
}
var json = JSON.stringify(data)
var fs = require('fs');
fs.writeFile('samples.json', json, 'utf8', function() {});
function startScan(i) {
var date1 = new Date();
wifi.scan(function(err, networks) {
if (err || networks.length == 0) {
console.log(" * [ERR] Failed to collect " + i + ". Waiting for a second before retrying... (" + err + ")")
utils.sleep(1000)
startScan(i);
return
}
console.log(" * [INFO] Collected sample " + i + " with " + networks.length + " networks in " + ( (new Date() - date1) / 1000 ) + "s")
samples.push(networks)
hook(i, networks);
if (i <= 1) return completion({samples: samples});
startScan(i-1);
});
}
async function listNetworks() {
networkList.innerHTML = "";
let networks = await wifi.scan().catch(err => {
console.error(err);
new Snackbar("We couldn't list available networks, check console.");
}) || [];
for (const hs of networks) {
if (connectedSSIDs.includes(hs.ssid)) continue;
let elem = document.createElement("button");
let strength = Math.ceil(hs.quality / 25);
let again = false;
elem.onclick = async function () {
if (!!hs.security.trim()) {
let message = document.createElement("div");
message.lead = document.createElement("p");
message.lead.className = "mb-2";
message.lead.innerHTML = `Network "${hs.ssid}" is secured. Enter hotspot's password.` +
(again ? "<br><div class="text-danger">Check the password you entered.</div>" : "");
message.pass = document.createElement("input");
function startScan(i) {
wifi.scan(function(err, networks) {
if (err || networks.length == 0) {
startScan(i);
return
}
if (i <= 0) {
return completion({samples: samples});
}
hook(i, networks)
samples.push(networks)
startScan(i-1);
});
}