friedrith / node-wifi

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

Fixed channel/frequency in `mac-current-connections.js` #11

Closed Kirbo closed 7 years ago

Kirbo commented 7 years ago

For some reason at first this worked just fine but when i started using node-wifi in Electron, i wasn't able to get any connections with this.

This change i've made fixed the issue, at least for me.

macOS Sierra, version: 10.12.4 (16E195)

I couldn't decide which is better:

connection.frequency = parseInt(networkUtils.frequencyFromChannel(parseInt(line.match(/[ ]*channel: (.*)/)[1])));

or:

connection.frequency = parseInt(networkUtils.frequencyFromChannel(parseInt(line.match(/[ ]*channel: (.*)/)[1].split(',')[0])));
friedrith commented 7 years ago

Oh god ! For the first one on this repo someone spent the time to create a PL ;)

I cannot test it for now on mac so I can only trust you. Can you please show the value of variable stdout (line 36 in file mac-current-connections.js) with standard node and electron ? Your PL is good for me but I just would like to analyze the difference between the 2 contexts to understand if the same difference might happens on other OS.

Kirbo commented 7 years ago

Now i've changed it into

connection.frequency = parseInt(networkUtils.frequencyFromChannel(parseInt(line.match(/[ ]*channel: (.*)/)[1].split(',')[0])));

For me the command /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport --getinfo sometimes has output:

...
...
           SSID: Pingu
            MCS: 9
        channel: 52,80

and sometimes (like now) has output:

...
...
           SSID: Pingu
            MCS: 9
        channel: 52

Might have something to do with my multiple wifi access points, don't know. But the code anyhow fetches the 52 out of the output, even if its channel: 52 or channel: 52,80 and with the current implementation in your master, it cannot find the network at all if the output has channel: 52 instead of channel: 52,80, because the RegExp is searching for channel: (.*),(.*) and since the line is in format channel: (.*) instead, it doesn't find anything.

friedrith commented 7 years ago

Ok You are right, I didn't expect to have several channels for the same network emitted by the same hotspot.

lock[bot] commented 4 years ago

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