friedrith / node-wifi Goto Github PK
View Code? Open in Web Editor NEW📶 NodeJS tool to manage wifi (connections, scans)
License: MIT License
📶 NodeJS tool to manage wifi (connections, scans)
License: MIT License
Hi. There's an issue with mac-current-connections.js where networkUtils.qualityFromDb(...) is called when the actual function in network-utils.js is called dBFromQuality. Just change the name and it's good to go. Thanks
To use the signal_level in my browser/server app I had to convert dB back to quality :-). One needs a percent to use with any level/progress component.
Best to just return both and let coders decide.
FYI, My web app is almost done. I've written a websocket server class wrapping node-wifi. Also a front end to access from a PWA (phone app). Will be a nice dependent to your module. End users will likely prefer want your module in this form.
BTW When I get done with my PWA I'd like to help with this project, answer issues, write PRs extending wrapping of nmcli. Thx.
Hi,
I'm confused, in the npmjs package this library is licensed as LGPL-3.0, but in this repository it is GPL-3.0.
Which license is it? Hopefully LGPL-3.0.
Could you please clarify it.
wifi.scan()
returns new error after updating from 2.0.5 to 2.0.7.
Should return list of networks
Returns error
Error: Command failed: nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags,device device wifi
Error: Could not create NMClient object: Could not connect: No such file or directory.
Workaround: Use 2.0.5 for now
Install node-wifi 2.0.7 on Debian Buster and run wifi.scan()
Just updating packages
when i request for available wifi networks than package exclude space in SSID.
i can't understand why you do this
scanResults = scanResults.toString('utf8').split(' ').join('').split('\n');
can you explain?
Hello,
It is working fine, when I run my nodejs project on my local development system,
but when I deploy my nodejs APP on azure ubuntu machine, it not deducting any wifi.
I have install network-manager on live azure ubuntu machine.
Currently testing on Lubuntu 17. Seems to work well!
One thing I have noticed is that if the specified password is incorrect, then the desktop session displays a (standard) prompt to the user for the wifi password. I would hope that I could have full control of the UI (or lack thereof). Any way around this?
macOs High Sierra - Version 10.13.6.
I have to be already connected to a wifi so that it gives me a list of wifis. If not, I only get empty list.
Then there's another problem for which might create another issue. I'm working on linux and mac parallel so when I scan for wifis on the mac I get sometimes the same wifi 4 times whereas on linux I don't get any duplicates.
When I try to connect to a secret SSID, I have the error :
Error: No network with SSID 'name' found
I think it's because nmcli need information about wifi before connection (like you can read here) :
nmcli c add type wifi con-name <connect name> ifname wlan0 ssid <ssid>
nmcli con modify <connect name> wifi-sec.key-mgmt wpa-psk
nmcli con modify <connect name> wifi-sec.psk <password>
nmcli con up <connect name>
I can't connect to wifi without sudo permission on Ubuntu 14.04, here is the message I get :
Error: Failed to add/activate new connection: (32) Not authorized to control networking.
Hi,
I am trying to scan for all the available networks around me, unfortonetly, most of the times I receive the following error: "can't read property 'match' of undefined".
Some of the times it works currectly.
Currently the only thing I do is setting the interface to null on the init() function (so the interface is selected randomly) and invoking the scan() function.
wifi.init({ iface: null }); wifi.scan();
Any idea what might gone wrong?
node-wifi/src/windows-connect.js
Line 34 in eeaef52
node-wifi/src/windows-connect.js
Line 52 in eeaef52
The windows connect function saves the new network profile under the filename "nodeWifiConnect.xml" but then immediately after uses the netsh command to add the profile using the filename (wifi ssid + ".xml"). This gives me the error, "stdout: 'The system cannot find the file specified.\r\n\r\n\r\n',". So line 34 should write the filename as (ap.ssid + ".xml") not "nodeWifiConnect.xml". After I made this change to the writeFileAsync and the following execCommand delete on line 46, my program connecting to the network successfully.
Would you be willing to change license to MIT?
Thanks.
Because, current version is still 1.2.5.
NetworkManager 1.10.X now uses a pager for most of the nmcli output. This breaks parsing. See https://bugzilla.gnome.org/show_bug.cgi?id=791808
I think if each nmcli command is prefixed with PAGER= as mentioned in the bug comments, this should get around the problem.
Can you help to export qualityFromDB in network-utils.js ? Just the same question as #57. thanks~~
Hey guys,
I need help with getCurrentConnections function. I need to get Promise back, I try to do if this way:
wifi.init({ iface : 'wlp3s0' });
wifi.getCurrentConnections().then(function (current) {
console.log(current)
}).catch(function (error) {
console.log(error)
})
I have this error instead:
/home//JavaScript/sandbox/main.js:8
wifi.getCurrentConnections().then(function (current) {
^
TypeError: Cannot read property 'then' of undefined
at Object.<anonymous> (/home/john/JavaScript/sandbox/main.js:8:29)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
But when I try to use it in my project, I get different error:
{ Error: Command failed: nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags,device device wifi ifname wlp3s0
Error: 'device wifi' command 'ifname' is not valid.
at ChildProcess.exithandler (child_process.js:275:12)
at emitTwo (events.js:126:13)
at ChildProcess.emit (events.js:214:7)
at maybeClose (internal/child_process.js:925:16)
at Socket.stream.socket.on (internal/child_process.js:346:11)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at Pipe._handle.close [as _onclose] (net.js:554:12)
killed: false,
code: 2,
signal: null,
cmd: 'nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags,device device wifi ifname wlp3s0' }
What can be wrong?
In Debian Jessie, the nmcli command does not return the FREQ field by default. This make the code not recognise the command's output and hence the library returns no networks.
Forcing all the fields in the result with the "-f all" option will solve this problem.
actually i start using node-wifi javascript libraries in angular 2 but i am getting error cannot find module "Child_process" so can you help me how i can use this library in angular 2.
urgent
1/ On Mac, install (the last version of) node-wifi with command npm install node-wifi
2/ In Hyper (a terminal), run node
3/ Copy paste the code
`var wifi = require('node-wifi');
// Initialize wifi module
// Absolutely necessary even to set interface to null
wifi.init({
iface : null // network interface, choose a random wifi interface if set to null
});
4/ Connect your computer to your wifi, with GUI.
5/ Copy paste the other code
// Connect to a network
wifi.connect({ ssid : "FreeWifi", password : ""}, function(err) {
if (err) {
console.log(err);
}
console.log('Connected');
});`
6/ Wait few seconds.
node-wifi try to connect FreeWifi SSID (it's a free wifi not secured in France from "Free" popular company). But failed. Mac reconnect your favorite wifi SSID. And node-wifi say "Connected" because no check the SSID connected.
Expectation : throw an error.
Would be nice to include this functionality as well
only showing empty array
window电脑调用 getCurrentConnections 出现多个进程 cmd和conhost
Although the case for WPA newtorks is taken into account in win32WirelessProfileBuilder
function, wpa2
value is hardcoded when connecting to a network if a password is given:
node-wifi/src/windows-connect.js
Line 16 in aad9b8e
Also, connecting to WEP protected networks is not supported on Windows.
TypeError: networkUtils.qualityFromDB is not a function
Need to define qualityFromDB
as an export in the utils file
O.S: Windows 10
Network name: Just a test
wifi.scan
returns:
frequency: "2412",
mac: "2a:a4:1c:95:e4:05",
security: "WPA2-Personal",
signal_level: -56.5,
ssid: "Justatest"
There are channels that you don't include and also different frequencies associated with the same channel on different bands (though it looks like they're mostly inconsequential since they aren't allowed in most places?). I should note I encountered this problem since the network I use (5GHz) gave me a channel of 149 on Windows.
Implementation code:
`
wifi.init({
iface: 'wlan0'
});
wifi.scan((error, networks) => {
if (error) {
console.log(error);
} else {
console.log(networks);
}
}
`
It raises an exception :
Cannot read property 'replace' of undefined at .../node_modules/node-wifi/src/linux-scan.js:23:29.
Line which caused the error: ssid: fields[1].replace(/&&/g, ':')
On some device like raspberry (raspbian) or ASUS Tinker Board (TinkerOS based on debian) we experienced issues because the 'list wifi' command with nmcli return the interface with the result of the scan like:
$ nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags device wifi list ifname wlan0 wlan0 yes:NETWORK_1:D4\:6E\:0E\:8E\:66\:EC:Infra:3:2422 MHz:78:WPA2:(none):pair_ccmp group_ccmp psk no:NETWORK_2:DA\:0F\:99\:70\:C4\:C2:Infra:6:2437 MHz:77:WPA2:(none):pair_ccmp group_ccmp psk no:NETWORK_3:40\:C7\:29\:D1\:BC\:A0:Infra:11:2462 MHz:50:WPA1 WPA2:pair_tkip pair_ccmp group_tkip psk:pair_tkip pair_ccmp group_tkip psk no:NETWORK_4\:C7\:29\:D5\:03\:08:Infra:1:2412 MHz:47:WPA1 WPA2:pair_tkip pair_ccmp group_tkip psk:pair_tkip pair_ccmp group_tkip psk
Testing fields length will do the job.
The nmcli I have return the "Signal level" as "67/100" and has no dBm so it fails on this line
else if (input.match(/Signal level=(.*) dBm/)) {
connection.signal_level = input.match(/Signal level=(.*) dBm/)[1];
}
if I remove the dBm from the regex it works fine
Sorry I didn't have the time to create a patch atm.
This stop it registering as a connection as the signal level is "0"
Andrew
I'm wondering why, at least on Windows (i haven't tested the behaviour on other OSs), when a connection is established to an open newtork, the connectionMode
is set to manual
. This prevents the machine from connecting to the chosen network again after a restart.
Is it a security reason? Does it happen on Linux and Mac?
When there is a wifi in reach using a channel >99 the parsing the airport output with the title indexOf will result in faulty data. E.g.
A Wifi 58:b8:f3:85:55:0e -84 44 Y DE WPA2(PSK/AES/AES)
Another Wifi 5 GHz 58:5e:12:48:35:24 -53 100,+1 Y DE WPA2(PSK/AES/AES)
will result in
ssid: "Another Wifi 5 GHz 58"
bssid: ":5e:12:48:35:24 -5"
signal_level: "3 10"
It could be fixed using a regexp like this: https://github.com/ancasicolica/node-wifi-scanner/blob/master/lib/airport.js#L10
the pass is't correct and the retur say it is correct
i put the incorrect pass and it say conected but don't realy conect
i use the examples in npmjs wep
version 2.0.4
Intel(R)Dual Band Wireless-Ac 3165
So have a function triggered, for instance, when the connection is lost? Or do I have to ping it constantly to monitor if there are any changes?
Implementation code:
wifi.init({
iface: 'wlan0'
});
wifi.scan((error, discoveredNetworks) => {
if (error) {
console.log(error);
} else {
console.log(discoveredNetworks);
}
}
The secondary throws the errorTypeError: Cannot read property 'replace' of undefined at /home/pi/*/node_modules/node-wifi/src/linux-scan.js:23:29
.
Line which caused the error: ssid: fields[1].replace(/\&\&/g, ':'),
.
Output of command nmcli -v
:
nmcli tool, version 1.6.2
Output of command nmcli
(I am only showing headers here):
eth0: connected to Wired connection 1
wlan0: disconnected
lo: unmanged
As the subject states. This does not seem to be working on Windows 10. I can scan for networks but when I connect to one I directly recieve the connected message but in fact the system is not connected at all. No errors are returned.
Curious if this could support creating ad-hoc networks?
I have a particular use case where I need the computer to host a WiFi network with a specified SSID and password. 2.4Ghz if it matters. DHCP addressing would be great too! :)
Hi,
I'm new to Node so please forgive me if this is dumb.
I have a code that detects wifi signals around me and set up a server for another page to grab it when I ran it locally. However, when I deployed it on Heroku, It just won't work. Is it because of that part of setting up a server or...? I would appreciate if you can spend some time looking at this. Thank you!
`
var express = require('express');
var app = express();
var wifi = require('node-wifi');
var parsedNetworks;
var cors = require('cors');
var towers0;
var ip = require('ip');
var myIP = ip.address();
var https = require('https');
var path = require('path');
var fs = require('fs');
console.log(myIP); // my ip address
/wifi/
app.use(cors())
wifi.init({
iface :null
});
wifi.scan(function(err, networks){
if(err){
console.log(err);
}else{
parsedNetworks = [];
towers0 = [];
networks.forEach(function(e){
parsedNetworks.push({'ssid': e.ssid, 'signal_level':e.signal_level, 'mac':e.mac, 'security':e.security})
})
for(i=0;i<networks.length;i++){
console.log(networks[i].ssid);
}
}
});
app.get('/getwifis', function (req, res) {
res.json(parsedNetworks);
})
var certOptions = {
key: fs.readFileSync(path.resolve('server.key')),
cert: fs.readFileSync(path.resolve('server.crt'))
}
var server = https.createServer(certOptions, app).listen(8081,function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at https://%s:%s", host, port)
})
`
Wei
It's only possible to connect with access point that needed a simple password.
That's a problem for Student and users of Eduroam for example
wifi.init thows error UNRECOGNIZED OS error running on raspbarry pi inside of a multi-container docker-compose file running node 10 in an electron/ react application. Im building the image via balenaOS
Expected it to recognize linux and use linux js files
just throws an error when on the pi. Works fine on a Mac within Electron
a way to specify the linux os via a param
I'm trying to display networks to a user via a react application. Basically, show user current wifi router and allow them to switch via the app.
Hi, thanks to read the issue, i didn't found a guideline to just open an issue.
(Currently working on a project that uses node-wifi inside an IoT device, nmcli tool, version 1.2.6)
So I was having troubles to get an updated list of visible APs, not sure if my issue is related with network manager but I seems that i find a way to make it works using nmcli device wifi rescan
before a wifi.scan();
only when i did that it works, so my question is if this is a specific workaround for me or it happens to someone else?
Hi,
in src/mac-scan.js I guess there is a small bug, quality calculation is maybe wrong:
In line 61 ff you have:
'signal_level' : lines[i].substr(colRssi, colChannel - colRssi).trim(),
'quality' : networkUtils.dBFromQuality(lines[i].substr(colRssi, colChannel - colRssi).trim()),
I guess it should be
'signal_level' : lines[i].substr(colRssi, colChannel - colRssi).trim(),
'quality' : networkUtils.QualityFromDB(lines[i].substr(colRssi, colChannel - colRssi).trim()),
The RSSI
column returns the DB level
and so you need to calculate the quality
based on the given level.
Hope, that I am not completely wrong ;-)
Regards
I get an error Error: Failed to add/activate new connection: (32) 802-11-wireless-security.psk: property is invalid
, which is the same error I get if I try and connect via nmcli dev wifi con "MY_SSID" password "MY_PASSWORD".
Hi,
I'm really interested in your code and what you are doing. I see that you wanted help on your npm page. Please let me know how to get started. Thanks!
Hi,
A quick question (not really an issue).
Is it possible to know on which current SSID the user is connected if she is?
And this should be an issue.
When I try to connect to SSID with a wrong password, I can't get back an error saying the password is wrong but I get connected to the last known SSID.
connectToWifi
's callback is called before the netsh
commands are run, instead of waiting for them to finish.
Also, when the connection fails (due e.g. to bad password, it'd be useful to remove the created profile).
the current command generates
nmcli dev disconnect iface wlan0
if iface is set
this should be
nmcli dev disconnect wlan0
change
if (config.iface) {
commandStr += " iface " + config.iface;
}
to
if (config.iface) {
commandStr += " " + config.iface;
}
scan keeps returning this extra bogus wap. Thei global installed cli version doesn't return this only from a programatic call to scan.
{ ssid: '--',
bssid: 'FA:8F:CA:60:8E:F2',
mac: 'FA:8F:CA:60:8E:F2',
mode: 'Infra',
channel: 3,
frequency: 2422,
signal_level: -50.5,
security: '',
security_flags: { wpa: '(none)', rsn: '(none)' },
quality: 99 } ]
It appears the fix for issue 26 has caused a new variant of issue 20 where the parser bombs but does not call the scan callback with the error. I think it's because the try/catch inside the exec() callback in windows-scan.js was removed. In my case the result is the process exits, I'm not sure if that's always true. Here's the current exception:
...\node_modules\node-wifi\src\windows-scan.js:47
network.mac = networkTmp[4].match(/.*?:\s(.*)/)[1];
^
TypeError: Cannot read property 'match' of undefined
at parse (E:\KPM\SrvWebs\vgr-system-server\node_modules\node-wifi\src\window
s-scan.js:47:32)
at E:\KPM\SrvWebs\vgr-system-server\node_modules\node-wifi\src\windows-scan.
js:33:27
at ChildProcess.exithandler (child_process.js:262:7)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at maybeClose (internal/child_process.js:927:16)
at Socket.stream.socket.on (internal/child_process.js:348:11)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at Pipe._handle.close [as _onclose] (net.js:545:12)
parse() throws the exception. The exec() callback function which called parse() doesn't have a try/catch, the try/catch you see is for the exec() call itself.
Frequently on a Windows 7 system the scan method bombs the node.exe process. The netsh output gets truncated (reason unknown), from what I've seen always after the Encryption line for some network. The parser then chokes
...\node_modules\node-wifi\src\windows-scan.js:66
var channelLine = networkTmp[7].split(' ').join('').split(':');
^
TypeError: Cannot read property 'split' of undefined
at parse (...\node_modules\node-wifi\src\window
s-scan.js:66:33)
at ...\node_modules\node-wifi\src\windows-scan.
js:41:15
at ChildProcess.exithandler (child_process.js:262:7)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at maybeClose (internal/child_process.js:927:16)
at Socket.stream.socket.on (internal/child_process.js:348:11)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at Pipe._handle.close [as _onclose] (net.js:545:12)
To avoid the crash I had to edit windows-scan.js and inside scanWifi() put a try/catch around most of the work, have the catch set err, and send err in the final callback instead of null (in a successful parse, the value of err is null). I could not find any way to catch this error with the released code.
Then in my callback if err is set I sleep for 20 seconds and call scan again, and it works.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.