friedrith / node-wifi

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

Return the network after connecting #92

Open FinlayDaG33k opened 5 years ago

FinlayDaG33k commented 5 years ago

Hii there,

node-wifi has the wifi.connect() method but this only returns anything if it there is an error.
When I manually tried connecting using the following command, however, I can get some more information (most notably, the interface used).

$ nmcli -w 10 device wifi connect REDACTED password REDACTED Device 'wlp2s0' successfully activated with 'REDACTED'.

Would it be an option to return the connection (things like ssid, bssid, iface etc. etc.) so we can extract some information that might be handy?
Right now what I do is wifi.connect(), wait for the connection to be finished then run wifi.getCurrentConnections(), wait for that to finish then do some additional checks so I can get the exact interface used.

friedrith commented 5 years ago

Hi, This is a good idea. We only need to be careful to have this feature on all OS. I guess you are on linux. And I am not sure windows command returns the same level of information. Feel free to propose a pull request.

FinlayDaG33k commented 5 years ago

Yes, I'm on Linux :) I'm already working on it though currently, I only have the interface information and not the rest of the connection.
I have created a PR so others can also join in.

valkheim commented 5 years ago

Hi @FinlayDaG33k What do you think about having a function that returns the connection status (connected, ssid, iface, dns, ...) independently from the wifi.connect(), so we can use it separately. That would fits your needs but also give the ability to use it at anytime. (See https://github.com/friedrith/node-wifi/issues/97 related issue)

FinlayDaG33k commented 5 years ago

That would indeed be a suiting alternative yes :)

valkheim commented 5 years ago

Hi,

I figured out that network manager sometimes fails to connect (rarely happens though) with the following message: Error: No network with SSID 'ssid' found.. Maybe we should add the possibility to try connecting for a pre-defined amount of times before returning an error ?

digaus commented 4 years ago

Any progress on this? I also think getting the current network information in a separate call is the better approach.

FinlayDaG33k commented 4 years ago

I haven't worked on it lately (mainly because I've forgotten about it since the app that I built using this hasn't been of much use for me since I don't travel by public transit a lot anymore)...

I do agree that having a separate call might be a better thing as well.

digaus commented 4 years ago

I am interested in this because of the integration of smarthome devices. Currently using Ionic Capacitor which supports Android, iOS and Electron. So I wanted to use this plugin to do the Wifi handling for a the electron application. For this I need to know the connected SSID and device IP, anyway great work so far :) might try it out later today.

FinlayDaG33k commented 4 years ago

@digaus Never heart of Ionic Capacitor before. I will check it out since it sounds interesting for my particular app as well.
My particular app is basically an app to make the use of captive portals a lot quicker by automating most of the stuff. All I really needed was the mac address of the specific network card connected to the AP (in case of multiple).

But yes, this would be quite handy.

stigmat4j commented 3 years ago

exec('nmcli -g ip4.gateway connection show ' + wifi.ssid, (err, ip) => { if(err) console.info(err); console.info(ip); });

work for me