Here are a some quick commands to manage and change your network settings in OSX.
- Turning Wi-Fi on or off
With the following options, you can get the power status of the current Wi-Fi card and change it if needed:
networksetup -getairportpower <device name>
networksetup -setairportpower <device name> <on off> - Setting the AirPort network
With these options you can change the network AirPort uses (see below for how to scan for Wi-Fi networks via the command line):
networksetup -getairportnetwork <device name>
networksetup -setairportnetwork <device name> <network> [password] - Managing preferred wireless networks
These options can be used to list your preferred Wi-Fi networks, add or remove networks to the list, or clear the entire list:
networksetup -listpreferredwirelessnetworks <device name>
networksetup -addpreferredwirelessnetworkatindex <device name> <network> <index> <security type> [password]
networksetup -removepreferredwirelessnetwork <device name> <network>
networksetup -removeallpreferredwirelessnetworks <device name>Along with the airport command which can also be used to scan for wifi networks.
- Airport
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
With the airport command you can change channels, disconnect from any Wi-Fi network, and get information on the current connection, but more importantly, you can scan for available Wi-Fi networks. If you don’t want to go digging for this buried command every time, you can make an alias for it, create a link to it, or copy it from its location to a more convenient place, such as the /usr/bin/ directory. Here, though, we will change to the command’s parent directory and run it from there by using the following:
cd /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/
Once at this directory, you can run various options in the command line to look up information and make changes to the Wi-Fi connection:
- Change channel
./airport -c CHANNEL - Disconnect
./airport -z - Get current connection info
./airport -I - Scan for Wi-Fi networks
./airport -s