Here RandMac class takes example_mac address and True value as class parameters simultaneously. Hence it is 6-byte address output contains the first 6 digits 0’s as a result.įinally, 12 byte MAC address generation is similar to 6-byte but we are sending true parameter to RandMac class. RandMac class takes this variable as a parameter and generates a new 6- byte MAC address and saves it in another variable called generated_mac, and we are printing it. We are giving an example MAC address to the example_mac variable. NOTE:- Output changes every time you run the program because it is similar to the random function. Print("Generated 6-byte mac address: ",generated_mac) So we should import Randmac module in our code.
Randmac module consists of a class called RandMac which generates random MAC addresses. Generating 6 – byte MAC Address in Python Make sure that your computer is connected to the internet. For installing it open Command Prompt and type the following command to install. Simultaneously need to install a module called Randmac. It is a 48-bit address embedded in a computer when manufacturing it.įirst of all, for this program to work we need Python 3.2 or greater, so make sure to upgrade python. These addresses are unique for each device. Similarly, computers have MAC addresses to communicate with other devices in the network. First of all, let us know what is the MAC Address.įor us to communicate with friends and relatives we have our house address.
#PYTHON MAC ADDRESS HOW TO#
In this article, we will learn about how to generate a random MAC address using Python.