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
Ethernet Address: N/A
Hardware Port: Ethernet
Ethernet Address: ff:ff:ff:ff:ff:ff
Hardware Port: FireWire
Ethernet Address: ff:ff:ff:ff:ff:ff:ff:ff
Hardware Port: Wi-Fi
Ethernet Address: ff:ff:ff:ff:ff:f
(Plan A #?) (Optional) Get the list of network interfaces only:
This step makes me easy to
$ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
(Plan A #2) Get the device name of the network interfaces.
I'd like to know which network interface(s) is/are active.
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
media: autoselect (none)
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet6 ffff::ffff:ffff:ffff:ffff%en1 prefixlen 64 scopeid 0x5
inet 192.168.1.fff netmask 0xffffff00 broadcast 192.168.1.fff
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
media: autoselect <full-duplex>
(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
(Plan B #2) Check current AirPort status:
$ ./airport -I
op mode: station
802.11 auth: open
link auth: fffffffffffffffff
(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:
$ blueutil status # Check status of BlueTooth
$ blueutil on # Turn BlueTooth on
$ blueutil off # Turn BlueTooth off
Now that I have all the ingredients, I can write the script for OS X 10.7!
(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)?