MAC address usage:
- Useful in places where the IP address changes frequently. Helps the network administrator. get information about network traffic.
- Helps us configure which computers can be connected to our computers. This way we can filter out potential spam / virus attacks.
- Helps in uniquely identifying computers from other computers around the world.
This article aims to extract the MAC address of a computer using Python.
Method 1: Using uuid.getnode ( )
getnode () can be used to retrieve the MAC address of a computer. This function is defined in the uuid module.
The illustrated code below shows how to generate a UUID for a given host, identified by its MAC address, using the uuid1 () function.
|
Output:
0x163e990b db
Disadvantage :
- The obvious disadvantage is that the output is not formatted.
Method 2: Using getnode () + format () [for better formatting]
|
Exit:
The MAC address in formatted way is: 00: 16: 3e: 99: 0b: db
Disadvantage :
- This code seems complicated.
Method 3: using getnode () + findall () + re () [to reduce complexity]
|
Exit:
The MAC address in formatted and less complex way is: 00: 16: 3e: 99: 0b: db