MAC address also known as physical address is the unique identifier that is assigned to the NIC (Network Interface Card) of the computer. NIC helps in connection of a computer with other computers in the network. MAC address is unique for all the NIC’s.
Uses of MAC address :
- Useful in places where IP address change frequently. Helps network admin. to get information regarding network traffic.
- Helps us to configure which computers can be connected to our computers. By this way we can filter potential spam/virus attacks.
- Helps in uniquely identifying computers from other computers around the world.
This article aims at extracting MAC address of computer using Python.
Method 1 : using mac module
To get the physical address of the device we use getmac module of Python.
>>>from getmac import get_mac_address as gma >>>print(gma()) '3c:7e:94:8f:d0:34'
Method 2 : Using uuid.getnode()
getnode() can be used to extract the MAC address of the computer. This function is defined in uuid module.
The illustrated code given below shows how to generate a UUID for a given host, identified by its MAC address, using the uuid1() function.
- The visible drawback is that the output is not in the formatted form.
Method 3 : Using getnode() + format() [ for better formatting ]
The MAC address in formatted way is : 00:16:3e:99:0b:db
- This code appears to be complex.
Method 4 : Using getnode() + findall() + re() [ for reducing complexity ]
The MAC address in formatted and less complex way is : 00:16:3e:99:0b:db
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Python - Extracting Key from Value Substring
- Python - Extracting Kth Key in Dictionary
- Python | Pandas Extracting rows using .loc
- Python - Extracting keys not in values
- Python | Extracting rows using Pandas .iloc
- Extracting email addresses using regular expressions in Python
- Python - Extracting Priority Elements in Tuple List
- Python program to validate an IP Address
- Python program to find IP Address
- Display Hostname and IP address in Python
- Check if email address valid or not in Python
- Python | Remove leading zeros from an IP address
- Python program to find if two IP Address belongs to Same or Different Network
- NLP | Extracting Named Entities
- Difference Between Network Address Translation (NAT) and Port Address Translation (PAT)
- Difference between MAC Address and IP Address
- Finding DBA from given IP address
- PyQt5 - GUI Application to get IP address
- Network Address Translation (NAT)
- Alias/Secondary IP Address
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : DivyaVishwakarma1