Is there a way to find out how the system is connected to the internet using Wifi or LAN?

3 Answers 3


You could start with the networksetup utility to list all current services available:

$~ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Thunderbolt Ethernet
Display Ethernet
Display FireWire
iPhone USB
Bluetooth PAN
Thunderbolt Bridge

Or you could list the service order:

$~ networksetup -listnetworkserviceorder
An asterisk (*) denotes that a network service is disabled.
(1) Thunderbolt Ethernet
(Hardware Port: Thunderbolt Ethernet, Device: en5)

(2) Display Ethernet
(Hardware Port: Display Ethernet, Device: en6)

(3) Display FireWire
(Hardware Port: Display FireWire, Device: fw0)

(4) Wi-Fi
(Hardware Port: Wi-Fi, Device: en0)

(5) iPhone USB
(Hardware Port: iPhone USB, Device: en4)

(6) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en3)

(7) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)

Then you can query each service to see if it's connected/configured e.g.

$~ networksetup -getinfo Wi-Fi
DHCP Configuration
IP address:
Subnet mask:
Client ID: 
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Wi-Fi ID: 6c:40:08:a9:62:50
  • is it possible to write a script for this? or a one-liner? and yes!! Many thanks your answer is satisfying. Mar 8, 2016 at 10:59

I like to use:

networksetup -listallhardwareports | grep -C1 $(route get default | grep interface | awk '{print $2}')

It checks which interface is currently used as default route and then looks up its hardware information.


Try this command:

networksetup -listnetworkserviceorder | grep -C1 $(netstat -nr | grep ^default | grep -o "\s\S\+$")

Basically it consist netstat:

$ netstat -nr | grep ^default
default         UGSc          399        0     en0

which gives you the default gateway IP address via which you connect to the internet. The relevant part is the last column which gives you name of the network interface (en0).

Since OS X is using the same name of interface for WiFi and wired ethernet (which is different for other Unixes), it's not possible to distinguish it by its name.

So this extra command should give you a clue which device it is:

$ networksetup -listnetworkserviceorder | grep -C1 en0
(3) Wi-Fi
(Hardware Port: Wi-Fi, Device: en0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.