31

I have been handicapped by the GUI and always seem to ask of help when it comes to the command line.

On Mac OS X only I need a command line to get the mac address of the wifi currently in use.

Help!

Prateek Gupta
  • 119
  • 2
  • 7
JVMX
  • 1,016
  • 2
  • 12
  • 23

6 Answers6

54

ifconfig en1 gets the interface details for wifi, the mac is on a line starting with ether, and is the second word on that line so:

ifconfig en1 | awk '/ether/{print $2}'
beresfordt
  • 5,088
  • 10
  • 35
  • 43
  • 3
    `awk` and `grep`? Why not just `ifconfig en1 | awk '/ether/{print $2}'` – Mark Setchell Feb 23 '15 at 23:10
  • 5
    How to know the WiFi interface index for sure? It seems like it's `en0` for some people so your code would fail – BullyWiiPlaza Aug 27 '17 at 17:08
  • 3
    @BullyWiiPlaza `networksetup -listallhardwareports` (see jarsever's answer) – Alex Oct 19 '18 at 06:04
  • 2
    For macbooks it's normally en0 these days, as per another answer `ifconfig en0 | awk '/ether/{print $2}'` – gingerCodeNinja Jul 07 '21 at 11:29
  • This is wrong, if your are on VPN and have additional CONX, you won't be able to get the right MAC address. I posted a solution that chooses the right Address below. – lac_dev Aug 27 '21 at 13:38
  • en1 interface doesnot always belongs to Wi-Fi. In my Mac, en1 interface belongs to Thunderbolt port 2 and en0 interface belongs to Wi-Fi – Karthik Mar 03 '22 at 07:31
25

I think the best and easiest way to get the information is using this command:

networksetup -listallhardwareports

It will return a nice list of devices like this:

Hardware Port: USB 10/100/1000 LAN
Device: en6
Ethernet Address: 00:e0:4c:...

Hardware Port: Wi-Fi
Device: en0
Ethernet Address: 80:e6:50:...

Hardware Port: Bluetooth PAN
Device: en3
Ethernet Address: 80:e6:50:...

Hardware Port: Thunderbolt 1
Device: en1
Ethernet Address: 72:00:05:...

Hardware Port: Thunderbolt 2
Device: en2
Ethernet Address: 72:00:05:...

Hardware Port: Thunderbolt Bridge
Device: bridge0
Ethernet Address: 72:00:05:...

VLAN Configurations
===================
jarsever
  • 690
  • 1
  • 7
  • 15
  • This command seems to always give you initial mac address. I changed it via `ifconfig ...` and `networksetup ...` still shows initial address not actual one. – Alex Oct 19 '18 at 06:06
12
networksetup -getmacaddress <interface>
nth
  • 1,442
  • 15
  • 12
  • 3
    It may be better to use this command: `networksetup -listallhardwareports` – jarsever Sep 20 '17 at 22:39
  • This command seems to always give you initial mac address. I changed it via `ifconfig ...` and `networksetup ...` still shows initial address not actual one. – Alex Oct 19 '18 at 06:06
7

This will easily give you the specific Mac Address for your Wifi Interface

networksetup -listallhardwareports | grep Wi-Fi -A 3 | awk '/Ethernet Address:/{print $3}'
lac_dev
  • 1,336
  • 14
  • 20
7

Wifi mac address is normally can be found in en0. So you may try this command on Terminal

ifconfig en0 | awk '/ether/{print $2}'
Pramodya Abeysinghe
  • 1,098
  • 17
  • 13
5

ifconfig should do the trick, it'll display a bunch of info including your MAC address. Alternatively it'll be in your network settings under system preferences.

EDIT

On a computer with just a wireless connection, en0 will have your wifi settings. The tag labeled with ether will most likely be your MAC address.

If you have both a wired and wireless connection, it'll be under ether in the en1 tag

Source: http://m.iclarified.com/entry/index.php?enid=30929

vkuo
  • 350
  • 1
  • 4
  • 21