A Media Access Control (MAC) address is a unique identifier assigned to network interfaces for communications. Typically, it is represented as six groups of two hexadecimal digits. Colons (:) separate those six groups. Each MAC Address is assigned uniquely to a specific device’s Network Interface Card (NIC). They are essential for network communication. Understanding MAC addresses is significant for managing and securing networked environments.
Using the uuid module of Python, we can obtain the MAC address through the getnode() method. The following example describes this method of extracting the MAC address:
Using uuid.getnode() and format() :
The uuid.getnode() method extracts the MAC address. To represent the obtained address in the six-group representation, we use the format() method.
import uuid addr = uuid.getnode() print(':'.join(['{:02x}'.format((addr >> x) & 0xff) for x in range(0,2*6,2)][::-1]))
Output:
3d:f5:d7:5e:78:e0