23 Commits

Author SHA1 Message Date
c16a65dbcd README.md aktualisiert 2024-03-27 22:11:38 +00:00
debd06f258 Fix null error; Fix promise 2024-03-27 22:16:56 +01:00
4e8c3efe6f test/airport.js gelöscht 2024-03-27 21:01:34 +00:00
330e851545 README.md aktualisiert 2024-03-27 21:00:57 +00:00
897314ee52 types/index.d.ts aktualisiert 2024-03-27 20:29:38 +00:00
4b751522b9 Add sudo 2024-03-27 20:28:43 +00:00
a4820acc34 index.js aktualisiert 2024-03-27 20:14:30 +00:00
b032feac3e index.d.ts aktualisiert 2024-03-27 20:05:05 +00:00
4a53c2f42a package.json aktualisiert 2024-03-27 19:58:49 +00:00
7314228c91 Dateien nach "/" hochladen 2024-03-27 19:55:54 +00:00
95b62bfbb0 README.md aktualisiert 2024-03-27 19:51:56 +00:00
91c43c5aac README.md aktualisiert 2024-03-27 19:50:58 +00:00
0f1a6d6661 New version added v1.1.3 2023-01-24 21:39:02 +01:00
9d42fb9b5e Improving mac OS part 2023-01-24 21:35:10 +01:00
0fe7bd8eed Merge remote-tracking branch 'origin/master'
# Conflicts:
#	package.json
2023-01-24 21:26:35 +01:00
a8416e1a27 Merge pull request #19 from soitgoes/auditfix
Auditfix
2023-01-24 21:25:59 +01:00
d7715d1cdf Merge remote-tracking branch 'origin/master' 2023-01-24 21:24:40 +01:00
36e1f8ffaf Merge pull request #15 from soitgoes/master
Accomodate for apples elimination of BSSID from airport results
2023-01-24 21:24:15 +01:00
cf885a3bdd Dependency updates only 2023-01-24 21:23:10 +01:00
ba0bfc7d42 upgrade npm modules causing audit flags 2022-12-21 10:25:35 -06:00
d0f22a8ed2 Remove unused var 2022-01-08 11:28:21 -06:00
a021a5d469 Accomodate for apples elimination of BSSID from airport results 2022-01-08 11:24:23 -06:00
9fe4300976 npm changed package.json 2019-10-27 15:08:32 +01:00
11 changed files with 2814 additions and 1243 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.idea
node_modules
/yarn.lock

View File

@ -1,4 +1,43 @@
#node-wifi-scanner
# Fork of node-wifi-scanner
This fork is used to add the ability to scan as sudo under linux.
Why the fork?
- Add ability to execute command with prefix 'sudo' to get iwlist working on linux!
- Uses promise instead of callback in module exports to make it easier and prevent callback hells.
- Add `encrypted:boolean` to the output, to determine if the network is encrypted (Currently only works under iwlist/linux, otherwise just returns false)
To use sudo, just pass `true` to the scan method and it will use sudo.
For ex.
```js
const wifiScan = require("node-wifi-scanner");
let result = await wifiScan.scan(true);
```
Beforehand you should add the iwlist scan command to the sudoers file.
`%mygroup ALL = (root) NOPASSWD: iwlist wlanX scan` [src](https://stackoverflow.com/questions/53710368/how-do-i-add-typescript-types-to-a-javascript-module-without-switching-to-typesc)
### Installation
`yarn add git+https://github.com/Tobstr02/node-wifi-scanner.git`
or `npm install git+https://github.com/Tobstr02/node-wifi-scanner.git`
### Type definitions
I also tried to add type definitions (see /types/index.d.ts), but as far as i know i did it wrong haha.
Since this is my first ever module (-fork) i don't really know how to do it. - Let me know in the issues tab or create a pull request :)
But i added jsdoc to the functions to add the ability to make the coding process a bit cleaner.
<br>
<i>Fork from: [Node-Wifi-Scanner Github](https://github.com/ancasicolica/node-wifi-scanner/)</i>
<br><br>
----
# Node-Wifi-Scanner
[![Build Status](https://travis-ci.org/ancasicolica/node-wifi-scanner.svg?branch=master)](https://travis-ci.org/ancasicolica/node-wifi-scanner)
[![npm](https://img.shields.io/npm/v/node-wifi-scanner.svg)]()
@ -16,39 +55,24 @@ system language. The adaptions needed would have been too comprehensive for a pu
## Operating Systems
It was tested with the following operating systems:
* Mac OS-X
* Windows 10
* Ubuntu 14.04
* Raspbian "Jessie"
* Mac OS-X [Not tested by fork author]
* Windows 10 [Not tested by fork author]
* Ubuntu 14.04 [Tested by fork author]
* Raspbian "Jessie" [Tested by fork author]
## Installation
npm i node-wifi-scanner
yarn add git+https://git.gaminggeneration.de/tobiash/node-wifi-scanner
## Usage
### Command Line
Run the script ```scan``` in the bin folder.
### Code
const scanner = require('node-wifi-scanner');
scanner.scan((err, networks) => {
if (err) {
console.error(err);
return;
}
console.log(networks);
});
The tool returns an array with objects, each object representing a network with the following properties:
* channel: WiFi channel
* ssid: SSID of the network (if available)
* mac: MAC Address of the network access point
* mac: MAC Address of the network access point (if available, otherwise empty string)
* rssi: signal strength
* encrypted: boolean - Is network encrypted?
In contrary to other wifi scanners no information about security is returned. This is due to the very different implementation
of the command line tools which do not allow a flawless detection.
@ -74,7 +98,7 @@ the operating system. Please note the following restrictions
before using this tool in a productive system.
**Linux**: iwlist does only return all found networks if run as sudo! Otherwise you'll
get only the network you're connected to.
get only the network you're connected to. <i>That's where my fork comes in!!</i>
**Windows**: there are some network cards which do not
return the MAC address and other parameters of the found networks. In this case
@ -86,7 +110,7 @@ card, OS,...) as available. Thanks
The MIT License (MIT)
Copyright (c) 2016 Christian Kuster
Copyright (c) 2016-2024 Christian Kuster, Tobias Hopp
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,3 +1,12 @@
/**
* @typedef {Object} WifiNetwork
* @property {string} ssid - SSID des WLAN-Netzwerks
* @property {string} mac - MAC-Adresse des WLAN-Netzwerks
* @property {number} channel - Kanal des WLAN-Netzwerks
* @property {number} rssi - Signalstärke des WLAN-Netzwerks (RSSI)
*/
/**
* node-wifi-scanner
* Created by kc on 04.04.16.
@ -57,10 +66,11 @@ function initTools(callback) {
/**
* Scan the networks with the scanner detected before
* @param callback
* @param {Function|any} callback
* @param {boolean} useSudo - Use sudo for access?
*/
function scanNetworks(callback) {
exec(scanner.cmdLine, function (err, stdout) {
function scanNetworks(callback, useSudo) {
exec((useSudo ? "sudo ":"") + scanner.cmdLine, function (err, stdout) {
if (err) {
callback(err, null);
return;
@ -71,20 +81,33 @@ function scanNetworks(callback) {
module.exports = {
/**
* Scan for wifis
* @param callback
*/
scan: function (callback) {
if (!scanner) {
initTools(function (err, s) {
* Funktion zum Scannen von WLAN-Netzwerken
* @param {boolean} useSudo? - Defaults to false | Should sudo be used to get the output?
* @return {Promise<WifiNetwork[]|null>} WiFinetwork Array or null
* @rejects Returns error on reject
*/
scan: function (useSudo = false) {
return new Promise( (resolve, reject) => {
if (!scanner) {
initTools(function (err, s) {
if (err) {
return callback(err);
return reject(err);
}
scanner = s;
scanNetworks(callback);
scanNetworks((err, result) => {
if(err)
return reject(err);
resolve(result);
}, useSudo);
});
return;
}
scanNetworks(callback);
scanNetworks((err, result) => {
if(err)
return reject(err);
resolve(result);
}, useSudo);
} );
}
};

View File

@ -7,8 +7,6 @@ const tool = '/System/Library/PrivateFrameworks/Apple80211.framework/Version
const cmdLine = tool + ' -s';
const detector = tool + ' -getInfo';
const macRegex = /([0-9a-zA-Z]{1}[0-9a-zA-Z]{1}[:]{1}){5}[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}/;
/**
* Parsing the output of airport (Mac OS X)
* @param str output of the tool
@ -22,17 +20,14 @@ function parseOutput(str, callback) {
let lines = str.split('\n');
for (let i = 1, l = lines.length; i < l; i++) {
let mac = lines[i].match(macRegex);
if (!mac) {
continue;
}
let macStart = lines[i].indexOf(mac[0]);
let elements = lines[i].substr(macStart).split(/[ ]+/);
if (lines[i] === '') continue;
let elements = lines[i].substring(51).split(/[ ]+/);
wifis.push({
'ssid' : lines[i].substr(0, macStart).trim(),
'mac' : elements[0].trim(),
'channel': parseInt(elements[2].trim(), 10),
'rssi' : parseInt(elements[1].trim(), 10)
'ssid' : lines[i].substring(0, 32).trim(),
'mac' : '', // There is no more mac on a mac
'channel': parseInt(elements[1].trim(), 10),
'rssi' : parseInt(elements[0].trim(), 10),
'encrypted': false,
});
}
}

View File

@ -13,6 +13,7 @@ const detector = tool + ' --help';
const macRegex = /([0-9a-zA-Z]{1}[0-9a-zA-Z]{1}[:]{1}){5}[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}/;
const cellRegex = /Cell [0-9]{2,} - Address:/;
const encryptedRegex = /Encryption key:on/g;
/**
* Parsing the output of iwlist, tool having a lot of different faces :-(
@ -27,7 +28,8 @@ function parseOutput(str, callback) {
let blocks = str.split(cellRegex);
blocks.forEach(block => {
let network = {};
let network = {encrypted: encryptedRegex.test(block)};
let lines = block.split('\n');
if (macRegex.exec(lines[0])) {
// First line is the mac address (always! (?))

View File

@ -41,7 +41,7 @@ function parseOutput(str, callback) {
// Basic rates (MBit/s) : 1 2 5.5 11
// Other rates (MBit/s) : 6 9 12 18 24 36 48 54
for (let i = 1, l = blocks.length; i < l; i++) {
let network = {};
let network = {encrypted: false};
let lines = blocks[i].split('\n');
let regexChannel = /[a-zA-Z0-9()\s]+:[\s]*[0-9]+$/g;
if (!lines || lines.length < 2) {

3779
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "node-wifi-scanner",
"version": "1.1.2",
"version": "1.1.3",
"description": "node.js module for WiFi network detection",
"main": "index.js",
"keywords": [
@ -13,19 +13,18 @@
"nmcli"
],
"author": {
"name": "Christian Kuster, CH-8342 Wernetshausen",
"email": "info@kusti.ch",
"url": "http://www.kusti.ch/"
"name": "Christian Kuster, Tobias Hopp",
"email": "tobi@gaminggeneration.de"
},
"homepage": "https://github.com/ancasicolica/node-wifi-scanner",
"homepage": "https://git.gaminggeneration.de/TobiasH/node-wifi-scanner/",
"bugs": {
"url": "https://github.com/ancasicolica/node-wifi-scanner/issues",
"url": "https://git.gaminggeneration.de/TobiasH/node-wifi-scanner/issues/",
"email": "info@ancasicolica.ch"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/ancasicolica/node-wifi-scanner.git"
"url": "https://git.gaminggeneration.de/TobiasH/node-wifi-scanner.git"
},
"engines": {
"node": ">= 4.0.0",
@ -35,12 +34,12 @@
"test": "mocha test"
},
"dependencies": {
"async": "3.1.0",
"lodash": "4.17.15"
"async": "3.2.4",
"lodash": "4.17.21"
},
"devDependencies": {
"grunt": "^1.0.3",
"grunt": "1.5.3",
"grunt-bump": "0.8.0",
"mocha": "6.2.0"
"mocha": "10.2.0"
}
}

View File

@ -1,67 +0,0 @@
/**
* Airport unit test
* Created by kc on 04.04.16.
*/
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const airport = require('../lib/airport');
describe('airport', () => {
it('parses the output of file 1', function(done) {
airport.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures','airport','airport01.txt'), { encoding: 'utf8' }), (err, info) => {
assert.ok(info);
assert.equal(info.length, 36);
let ap = info[0];
assert.equal(ap.mac, '00:35:1a:90:56:03');
assert.equal(ap.ssid, 'OurTest');
assert.equal(ap.rssi, -70);
assert.strictEqual(ap.channel, 112);
ap = info[19];
assert.equal(ap.mac, '00:35:1a:5b:45:b6');
assert.equal(ap.ssid, 'PDANet1');
assert.equal(ap.rssi, -78);
assert.strictEqual(ap.channel, 11);
ap = info[25];
assert.equal(ap.mac, '10:bd:18:ab:4d:8f');
assert.equal(ap.ssid, 'TEST Training');
assert.equal(ap.rssi, -71);
assert.strictEqual(ap.channel, 6);
ap = info[35];
assert.equal(ap.mac, '00:35:1a:90:56:00');
assert.equal(ap.ssid, 'TEST-Wifi');
assert.equal(ap.rssi, -67);
assert.strictEqual(ap.channel, 1);
done(err);
});
});
it('parses the output of file 2', function(done) {
airport.parseOutput(fs.readFileSync(path.join(__dirname, 'fixtures','airport','airport02.txt'), { encoding: 'utf8' }), (err, info) => {
assert.ok(info);
assert.equal(info.length, 4);
let ap = info[0];
assert.equal(ap.mac, '7c:b7:33:ae:3b:06');
assert.equal(ap.ssid, 'Raupo');
assert.equal(ap.rssi, -80);
assert.strictEqual(ap.channel, 64);
ap = info[3];
assert.equal(ap.mac, '7c:b7:33:ae:3b:04');
assert.equal(ap.ssid, 'Visitor Raupo');
assert.equal(ap.rssi, -66);
assert.strictEqual(ap.channel, 9);
done(err);
});
});
});

View File

@ -1,5 +1,5 @@
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
OurTest 00:35:1a:90:56:03 -70 112 Y CH WPA2(PSK/AES/AES)
OurTest -70 112 Y CH WPA2(PSK/AES/AES)
OurDev 00:35:1a:90:56:04 -70 112 Y CH WPA2(PSK/AES/AES)
PDANet1 00:35:1a:90:56:09 -70 112 Y CH WPA2(PSK/AES/AES)
TEST-Wifi 00:35:1a:90:56:0f -70 112 Y CH WPA2(PSK/AES/AES)

41
types/index.d.ts vendored Normal file
View File

@ -0,0 +1,41 @@
declare module 'node-wifi-scanner' {
type Callback<T> = (error: Error | null, result: T | null) => void;
interface WifiNetwork {
ssid: string;
mac: string;
channel: number;
rssi: number;
}
interface Scanner {
cmdLine: string;
parseOutput(output: string, callback: Callback<WifiNetwork[]>): void;
}
interface Tool {
detector: string;
}
const airport: Tool;
const iwlist: Tool;
const netsh: Tool;
/**
* Initialize the scanner tools
* @param callback Callback function
*/
function initTools(callback: Callback<Scanner>): void;
/**
* Scan the networks
* @param callback Callback function
*/
function scanNetworks(callback: Callback<WifiNetwork[]>): void;
/**
* Scan for WiFi networks
* @param callback Callback function
*/
function scan(callback: Callback<WifiNetwork[]>): void;
}