Using networksetup for Wi-Fi networks on OS X systems

On a Mac OS X system, such as a MacBook Pro laptop, you can use the networksetup command to view information for Wi-Fi networks and manage wireless network connections. You can run the command from a shell prompt, aka command-line interface (CLI), using the Terminal application included with OS X, which is found in the Applications/Utilities folder.

You can see if a system supports wireless connections using the command networksetup -listallnetworkservices. You should see "Wi-Fi" listed when you run the command.

$ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Bluetooth DUN
Ethernet
FireWire
Wi-Fi

To determine the device interface that supports Wi-Fi connections on the system, use the command networksetup -listallhardwareports.

$ networksetup -listallhardwareports

Hardware Port: Bluetooth DUN
Device: Bluetooth-Modem
Ethernet Address: N/A

Hardware Port: Ethernet
Device: en0
Ethernet Address: d4:9a:20:0d:e6:ec

Hardware Port: FireWire
Device: fw0
Ethernet Address: d4:9a:20:ff:fe:0d:e6:ec

Hardware Port: Wi-Fi
Device: en1
Ethernet Address: f8:1e:df:d9:2b:64

VLAN Configurations
===================

In the example above, the device name for the Wi-Fi port is en1. That device name is needed for some of the other networksetup commands you may use.

If the system is currently connected to a wifi network, you can get information such as the IP addres, subnet mask, gateway address ,etc. using the command networksetup -getinfo Wi-Fi.

$ networksetup -getinfo Wi-Fi
DHCP Configuration
IP address: 192.168.167.13
Subnet mask: 255.255.255.0
Router: 192.168.167.1
Client ID: 
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Wi-Fi ID: f8:1e:df:d9:2b:64

If you wish to view the wireless networks the system is familiar with and will try to connect to, you can use the command networksetup -listpreferredwirelessnetworks device_name, where device_name is the port used for Wi-Fi connections. E.g.:

$ networksetup -listpreferredwirelessnetworks en1
Preferred networks on en1:
	casa
	Guest-VNE
	Wave1
	RESIDENCEINN
	T28J5
	Hazel
	attwifi
	Imp
	Chasehotel
	Hunt Valley Inn
	belkin.c76
	casaguest
	ummc-guest
	rms-guest
	VA Internet
	CableWiFi
	xfinitywifi
	HTC6435LVW 0A B3
	ARRIS-0142
	ARRIS-0142-5G

To see which wifi network the system is currently connected to, you can use the command networksetup -getairportnetwork device_name.

$ networksetup -getairportnetwork en1
Current Wi-Fi Network: Guest-VNE

If you wish to use a specific Wi-Fi network, you can use the command networksetup -setairportnetwork device_name wifi_network password. If the wifi network is an unsecured one that doesn't require you to know a WPA/WEP key in order to connect, you can omit the password at the end of the command. If you are already connected to a wifi network, the connection will be switched to the one you specify.

$ networksetup -setairportnetwork en1 casa

The SSID for a network is case-sensitive, so, if the network SSID is "casa", you need to specify "casa" not "CASA". If a password value is specified, it will be stored in the keychain. I have not found that specifying a password on the line to work for a wireless network that requires 802.1X authentication.

You can have different wifi networks associated with different locations. To view the locations that the system is aware of for wireless networks, you can use the command networksetup -listlocations.

$ networksetup -listlocations
ACI
Chesapeake College
Imp
VNE Guest
Automatic
Home

To switch to a particular location, you can use the command networksetup -switchtolocation location_name. A location can be deleted with the command networksetup -deletelocation location_name.

You can turn the Wi-Fi connection off and on, i.e., you can enable/disable it, using the command networksetup -setairportpower device_name on/off .

Aiseesoft Mac Video Converter Ultimate
$ networksetup -getairportnetwork en1
Current Wi-Fi Network: casa
$ networksetup -setairportpower en1 off
$ networksetup -getairportnetwork en1
You are not associated with an AirPort network.
Wi-Fi power is currently off.
$ networksetup -setairportpower en1 on
$ networksetup -getairportnetwork en1
Current Wi-Fi Network: casa

If you set the power to off and then set it to on, you will be automatically connected to your preferred Wi-Fi network as shown above. You can check whether Wi-Fi has been enabled or disabled with the setairportpower option using the getairpower option.

$ networksetup -getairportpower en1
Wi-Fi Power (en1): On

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px

Valid HTML 4.01 Transitional

Created: Wednesday December 2, 2015