A media access control address (MAC address) of a device is a unique identifier assigned to a network interface controller (NIC) for communications at the data link layer of a network segment. MAC addresses are used as a network address for most IEEE 802 network technologies, including Ethernet and Wi-Fi.
In Microsoft Windows, getting MAC Address is very easy task but in Linux, there are so many different ways through which you can get the MAC Address and especially if you are doing some BASH/Python work, its very important that you should get the MAC Address in just one line without any extra information about the interface.
On Linux systems, the Ethernet device is typically called eth0. In order to find the MAC address of the Ethernet device, you must first execute all the below commands as a root.
The MAC address is often printed on a label attached to the device, or printed on the box it came in. Otherwise, you can check the below commands where we’ve explained the process for getting the MAC Address by 10 different ways.
Method 1 –
With the help of below command, you can easily find out the MAC Address of your Kali Linux machine.
Command: ifconfig | grep ether
Method 2 –
With the help of below command, you can easily print out the MAC address directly from your current interface (eth0) file which is located at /sys/class/net/eth0/address.
Command: cat /sys/class/net/eth0/address
And if you want to display all Interface’s MAC Address, then type “cat /sys/class/net/*/address”
Method 3 –
With regix expression along with grep utility, will also helps you to get the MAC Address of any interface.
Command: ifconfig eth0 | grep -o -E ‘([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}’
Method 4 –
With (IP) command, you can also finds out the MAC Address of any interface along with some more information about the network like broadcast address, link speed and mode etc.
Command: ip link show eth0
And if you simply want to display the MAC address, then you can use the below command:
Command: ip link show eth0 | awk ‘/ether/ {print $2}’
Method 5 –
You can also use the below command to get the MAC Address of any interface along with some more information as shown in below screenshot:
Command: ip addr | grep -C1 “link/ether”
Method 6 –
With simply ifconfig and grep command, you can also get the same MAC address of any interface.
Command: ifconfig eth0 | grep -Eo ..\(\:..\){5}
Method 7 –
With IP LINK SHOW command, the same process can be done in just a single command.
Command: LANG=C ip link show | awk ‘/link\/ether/ {print $2}’
Method 8 –
To find out the MAC address, you can also use one open source tool called as “ethtool” which is already pre-installed in Kali Linux OS.
Command: ethtool -P eth0 | awk ‘{print $NF}’
Method 9 –
If you are good in python, then you can use the below script for displaying the MAC address of all interfaces.
Code:
#yeahhub.com
import os
sys_net = ‘/sys/class/net’
for dev in os.listdir(sys_net):
with open(os.path.join(os.path.join(sys_net, dev), ‘address’)) as f:
print dev, f.read(),
Simply save the file in .py extension and execute the file with below command:
Command: python findmac.py
Method 10 –
Dmesg is another free open source utility, through which you can easily get out the MAC address of any interface.
You may also like:Command: dmesg | grep eth
- Most Common DNS Record Types and Their Roles
- Top Skills Needed to Become a Cybersecurity Analyst
- Mastering Windows Management with WMIC Commands – Top 20 Examples
- Edit and Compile Code with the Best 5 Code Editors
- 50+ Top DevSecOps Tools You Need To Know
- Learn How to Add Proxy and Multiple Accounts in MoreLogin
- Some Useful PowerShell Cmdlets
- Create Free SSL Certificate – ZEROSSL.COM [2020 Tutorial]
- Generate Self-Signed SSL Certificate with OPENSSL in Kali Linux
- RDP – CredSSP Encryption Oracle Remediation Solution 2020