|
Answer» How to extract MAC Address by using Python define four ways to do that? As we KNOWS thet MAC Address is known as physical address which is UNIQUE identifier and that is assigned to NIC of Computer. MAC Address is useful in place of IP Address as IP Address change FREQUENTLY. Below are the 3 ways to get MAC Address by using python syntax:- (1)By using below code we will get Mac Address
 (2)By using uuid.getnode() method # Code to compute MAC address of host # By using UUID module import uuid # print value of unique MAC by getnode() function print (hex(uuid.getnode()))
But in above method format is not as per requirement we need to change that
(3)By using getnode() +format() # Python 3 code to print MAC in formatted WAY. import uuid print ("MAC address formatted way : ", end="") print (':'.join(['{:02x}'.format((uuid.getnode() >> ele) & 0xff) for ele in range(0,8*6,8)][::-1]))
(4)By using Using getnode() + findall() + re() # Python 3 code to print MAC formatted way import re, uuid # joins elements of getnode() after each 2 digits by using regex expression print ("The MAC address in formatted and less complex way is : ", end="") print (':'.join(re.findall('..', '%012x' % uuid.getnode())))
|