Depending on my objective (Should I concern about shutting down data interface as well?), I can choose the plan accordingly:
Plan A for (1) Network Interfaces and (2) Data Interface
Plan B for (1) Network Interfaces
(Plan A #1) Get installed hardware interfaces info (including data interfaces):
First, I'd like to know how many and what types of interfaces I should worry about.
$ networksetup -listallhardwareports
Hardware Port: Bluetooth DUN
Device: Bluetooth-Modem
Ethernet Address: N/A
Hardware Port: Ethernet
Device: en0
Ethernet Address: ff:ff:ff:ff:ff:ff
Hardware Port: FireWire
Device: fw0
Ethernet Address: ff:ff:ff:ff:ff:ff:ff:ff
Hardware Port: Wi-Fi
Device: en1
Ethernet Address: ff:ff:ff:ff:ff:f
(Plan A #?) (Optional) Get the list of network interfaces only:
This step makes me easy to grep
.
$ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Ethernet
FireWire
Wi-Fi
(Plan A #2) Get the device name of the network interfaces.
I'd like to know which network interface(s) is/are active.
$ ifconfig
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether ff:ff:ff:ff:ff:ff
media: autoselect (none)
status: inactive
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether ff:ff:ff:ff:ff:ff
inet6 ffff::ffff:ffff:ffff:ffff%en1 prefixlen 64 scopeid 0x5
inet 192.168.1.fff netmask 0xffffff00 broadcast 192.168.1.fff
media: autoselect
status: active
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
lladdr ff:ff:ff:ff:ff:ff:ff:ff
media: autoselect <full-duplex>
status: inactive
(Plan B #1) Locate airport
command or set alias for airport
command if not recognized:
My system couldn't recognize airport
command, so I had to add below line to .bash_profile
.
alias airport='/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport'
(Plan B #2) Check current AirPort status:
$ ./airport -I
agrCtlRSSI: -10
agrExtRSSI: 0
agrCtlNoise: -10
agrExtNoise: 0
state: running
op mode: station
lastTxRate: 100
maxRate: 100
lastAssocStatus: 0
802.11 auth: open
link auth: fffffffffffffffff
BSSID: ff:ff:ff:ff:ff:ff
SSID: MelvNetwork
MCS: 15
channel: 6
(Plan A & B #3)Turning on/off the AirPort:
# For OS X 10.7 and later
$ networksetup -setairportpower en1 on # Turn on Airport
$ networksetup -setairportpower en1 off # Turn off Airport
# for OS X 10.6 and below
$ networksetup -setairportpower on # Turn on AirPort
$ networksetup -setairportpower off # Turn off AirPort
(Plan A & B #4)Turning on/off the BlueTooth:
Download blueutil
here.
$ blueutil status # Check status of BlueTooth
Status: on
$ blueutil on # Turn BlueTooth on
$ blueutil off # Turn BlueTooth off
Script:
Now that I have all the ingredients, I can write the script for OS X 10.7!
Last Comments:
(1) Some of the output are masked with the character 'f'.
(2) According to $ man networksetup
, you can configure the proxy, TCP/IP, PPPoE as well (not tested).
(3) @RichHomolka's suggestion, networksetup --enableuserprofile
is deprecated for OS X 10.7 (not tested in other versions).
(4) If anyone following the above procedure encounters a problem, could you please address them in the comment (or as in a separate answer)?