-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifiScanner.js
40 lines (36 loc) · 1.24 KB
/
wifiScanner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const wifi = require('node-wifi');
// Initialize wifi module
wifi.init({
iface: null // network interface, choose a random wifi interface if set to null
});
let knownDevices = new Set();
function scanWifiNetworks(callback) {
wifi.scan((err, networks) => {
if (err) {
console.error('Error scanning WiFi networks:', err);
callback([], []); // Return empty arrays in case of error
} else {
const newDevices = [];
networks.forEach(network => {
if (!knownDevices.has(network.bssid)) {
knownDevices.add(network.bssid);
newDevices.push({
mac: network.mac || '',
bssid: network.bssid || '',
ssid: network.ssid || '',
channel: network.channel || 1,
frequency: network.frequency || 2412,
signal_level: network.signal_level || '-18',
quality: network.quality || 164,
security: network.security || 'RSN',
security_flags: network.security_flags || ['(PSK/AES/AES)']
});
}
});
console.log('Known Devices:', Array.from(knownDevices));
console.log('New Devices Detected:', newDevices);
callback(networks, newDevices);
}
});
}
module.exports = { scanWifiNetworks };