简体   繁体   English

用于在 OS X 中获取 mac 地址的 Shell 命令

[英]Shell command for getting mac address in OS X

I have been handicapped by the GUI and always seem to ask of help when it comes to the command line.我一直受到 GUI 的影响,似乎总是在命令行方面寻求帮助。

On Mac OS X only I need a command line to get the mac address of the wifi currently in use.在 Mac OS X 上,我只需要一个命令行来获取当前使用的 wifi 的 mac 地址。

Help!帮助!

ifconfig en1 获取 wifi 的接口详细信息,mac 位于以 ether 开头的行上,并且是该行上的第二个字,因此:

ifconfig en1 | awk '/ether/{print $2}'

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
===================
networksetup -getmacaddress <interface>

ifconfig should do the trick, it'll display a bunch of info including your MAC address. ifconfig应该可以解决问题,它会显示一堆信息,包括您的 MAC 地址。 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.在只有无线连接的计算机上,en0 将拥有您的 wifi 设置。 The tag labeled with ether will most likely be your MAC address.标有 ether 的标签很可能是您的 MAC 地址。

If you have both a wired and wireless connection, it'll be under ether in the en1 tag如果您同时具有有线和无线连接,它将在 en1 标签中的 ether 下

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

这将轻松为您提供 Wifi 接口的特定 Mac 地址

networksetup -listallhardwareports | grep Wi-Fi -A 3 | awk '/Ethernet Address:/{print $3}'

Wifi mac address is normally can be found in en0. Wifi mac地址通常可以在en0中找到。 So you may try this command on Terminal所以你可以在终端上试试这个命令

ifconfig en0 | awk '/ether/{print $2}'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM