Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect to preferred (saved) network via networksetup without password

I am trying to connect to a secured Wifi via the networksetup command (OSX), without re-entering the WPA2 password (assuming the user had entered and saved it before).

I basically want to temporarily switch to another (known) Wifi, then afterwards connect back to the previous one without asking the user for the password.

networksetup -getairportnetwork en0 returns the current network (so I know where to connect back to)

networksetup -setairportnetwork en0 WIFI_SSID_I_WANT_TO_JOIN sounds like my friend, but requires a password. Not specifying a password leads to a failed attempt of connecting without password.

networksetup -listpreferredwirelessnetworks en0 returns a list of all stored networks that OSX can connect to automatically.

I can't seem to find a way to reconnect to an existing network (from the preferredwirelessnetworks list). Is there a way to do that?

like image 552
Daniel Avatar asked Oct 31 '22 07:10

Daniel


1 Answers

By using the following two commands, it is possible to reconnect to a saved network.

networksetup -setairportpower en0 off # turn off device en0
networksetup -setairportpower en0 on  # turn on device en0

However, this solution cannot specify the network which to connect if there are multiple network configuration saved.

like image 188
bamb00dark Avatar answered Nov 15 '22 05:11

bamb00dark