friedrith / node-wifi

📶 NodeJS tool to manage wifi (connections, scans)
MIT License
398 stars 161 forks source link

[Bug]: Returning [] empty array on macOS Monterey #171

Closed juanmartin closed 2 years ago

juanmartin commented 3 years ago

Expected behavior

When scanning networks either by node API using wifi.scan or with the CLI using npx node-wifi-cli --scan Should return list of scanned networks.

Current behavior

When scanning networks either by node API using wifi.scan or with the CLI using npx node-wifi-cli --scan, it returns [] an empty array. No errors, just an empty list.

Which are the affected features

Which is your operating system?

MacOS

Environment

Version of node-wifi

2.0.15

Steps to Reproduce

Scan networks by either CLI or node-wifi api and log the result.

Solutions

I'm wondering if there are any new permissions to manage the wifi hardware on Monterey. There were no dialogs shown whatsoever when trying to use the CLI or the node app we are developing that relies on this lib.

Also tried using debug: true as a parameter for the wifi.init but couldn't see any additional info when logging the resulting networks.

friedrith commented 3 years ago

The debug true is not usable yet.

Can you try to use command /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --scan?

juanmartin commented 3 years ago

Hi! thanks for the follow up. The command runs fine and shows available networks.

friedrith commented 3 years ago

I guess the output format is slightly different between Big Sur and Monterey. Can you share an output of the command node scripts/scan.js? I suggest you to change few letters in ssid and mac addresses for privacy.

Thank you for your help. Monterey is significant up coming target for the project node-wifi.

juanmartin commented 3 years ago

Sure!

node scripts/scan.js
$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --scan
                            SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                    XXXX-AMPLIFI                   -81  36      Y  -- WPA2(PSK/AES/AES) 
                    XXXX-AMPLIFI                   -65  36      Y  -- WPA2(PSK/AES/AES) 
                     XXXX-2.4GHz                   -27  11      Y  -- WPA(PSK/TKIP,AES/TKIP) WPA2(PSK/TKIP,AES/TKIP) 
                       XXXX-5GHz                   -33  149     Y  -- WPA(PSK/TKIP,AES/TKIP) WPA2(PSK/TKIP,AES/TKIP)
friedrith commented 3 years ago

The bssid field is totally empty on your output or just cleaned it yourself?

juanmartin commented 3 years ago

totally empty, I only edited the XXXX in the SSIDs.

friedrith commented 3 years ago

Ok perfect. I look into your issue.

friedrith commented 3 years ago

So using your log file I can reproduce the problem in the parser. I see 2 options:

Can you tell me if bssid is included in one of the following commands?

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport scan

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s -x
juanmartin commented 3 years ago

I think you'll be able to do option 2 with the second command, it returns in XML/plist format including bssid.

airport scan doesn't return bssid, it's equivalent to --scan airport-scan.log

airport -s -x gives xml/plist format with everything airport-sx.log

Hope it helps. Thank you!

friedrith commented 3 years ago

Yes it helps a lot. Besides using xml is safer than parsing the command output. It was in the roadmap but I guess we just have to reprioritize this feature. I will work on it.

juanmartin commented 2 years ago

Hi @friedrith any updates on this? Monterey is coming next Monday 😅 Let me know if I can provide any help :D

friedrith commented 2 years ago

Oups. I started but it is not finished yet. I might be able to push you a version for wednesday evening PT. I am currently hesitating between the xml parser to use. The goal is to have node-wifi library as small as possible since the roadmap was to remove all third party dependencies.

juanmartin commented 2 years ago

I see, tough choice! I've used xml-js in the past but I understand your desire of removing all 3rd parties. Careful not to over-engineer with complex RegEx, though!

Thank you for your great work. I'm looking forward to test the upcoming version.

friedrith commented 2 years ago

I am struggling to include refactorizations I was working on for few months. Is it possible to try this alpha: https://www.npmjs.com/package/node-wifi/v/2.1.0-alpha.1 on Big Sur.

It doesn't include the fix for Monterey but includes refactorizations I might include in the fix for Monterey.

friedrith commented 2 years ago

I noticed that sometimes using command airport --scan --xml macOS kills the command before the end and the standard output doesn't include a well formatted XML. It happens mostly when you have a high number of wifi networks.

I don't know if this problem happens only on my computer.

So temporarily, I propose fix number 1: the result doesn't include the bssid but at least everything else is there. You can check the version before I release it: https://www.npmjs.com/package/node-wifi/v/2.0.16-alpha.0.

juanmartin commented 2 years ago

Thanks for the updates! Tested both versions in our app and both seem to be working fine. Also tested npx node-wifi-cli --scan and returned ok, but not sure if that package includes the latest work you've done. All this on Big Sur. Not including the BSSID wouldn't be an issue for general use case I guess. At least not for us. So your fix sounds good to me. Or you could add a warning ¯_(ツ)_/¯

This is a screenshot of a collaborator running airport --scan --xml on Monterey beta, notice he had to use the full path as airport didn't seem to be in $PATH or something.

friedrith commented 2 years ago

Ok I will publish the alpha 2.0.16-alpha tomorrow without the bssid for Montery with a warning.

For node-wifi-cli, what do you mean by it returned ok? It returned the good output or the string "ok"? I think node-wifi-cli has a bug but just in delete connection. Scan should be ok.

Once node-wifi will be published, I will update node-wifi-cli too. So far it doesn't include the fix.

Yes airport is never in macOS PATH so you always have to use the absolute path. I didn't explicitely use it in my last message to simplify but I should have been more accurate.

juanmartin commented 2 years ago

Great! looking forward to try that one out on Monterey 🚀

Sorry, I meant node-wifi-cli returned the expected results for the scan :D

I had the memory that I once used airport without the full path, but yeah I guess I was wrong.

Thanks again!

friedrith commented 2 years ago

node-wifi and node-wifi-cli fixes have been released. I hope it will work for you.

juanmartin commented 2 years ago

Confirm it's working on Monterey!!! 🎉 Thank you for everything! 🚀 Much appreciated, keep it up! great lib :D

friedrith commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.