How to check status of Wi-Fi adapter through command line?
Solution 1:
You can use the ifconfig
command, e.g.:
$ ifconfig en0
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether # Removed for Security.
inet6 fe80::c44:6ce5:5d57:5b93%en0 prefixlen 64 secured scopeid 0x9
inet 192.168.2.101 netmask 0xffffff00 broadcast 192.168.2.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
$
You can also filter the output, e.g.:
$ ifconfig en0 | awk '/status:/{print $2}'
active
$
When not active the output is, e.g:
$ ifconfig en0 | awk '/status:/{print $2}'
inactive
$
If you do not know the device name for the Wi-Fi network adapter, you can use the following examples:
$ networksetup -getairportpower $(system_profiler SPAirPortDataType | awk -F: '/Interfaces:/{getline; print $1;}')
Wi-Fi Power (en0): On
$
Or:
$ ifconfig $(system_profiler SPAirPortDataType | awk -F: '/Interfaces:/{getline; print $1;}') | awk '/status:/{print $2}'
active
$
Solution 2:
Actually, networksetup has the command to return the status of airportpower as well.
networksetup -getairportpower *specify the interface*
For example:
networksetup -getairportpower en0
Solution 3:
In addition to ifconfig
and networksetup
, there's also the airport
command. It's in an obscure location, so you have to specify the entire path to it (or make an alias, like I have). I find the -I
(show current status) and -s
(scan for networks) options most useful (although they're considered "legacy"). Here's an example:
$ alias airport=/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
$ airport -I
AirPort: Off
$ # [Switches radio on...]
$ airport -I
agrCtlRSSI: -49
agrExtRSSI: 0
agrCtlNoise: -88
agrExtNoise: 0
state: running
op mode: station
lastTxRate: 300
maxRate: 300
lastAssocStatus: 0
802.11 auth: open
link auth: wpa2-psk
BSSID: 88:d7:f6:25:c4:37
SSID: NotMyRealName
MCS: 15
channel: 40,-1
You can use the -h
flag to get a list of its options.