Tutorial: MAC Address Generator Code

August 20, 2017 | Views: 4061

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

Today, I will present a random MAC address generator tool written in Python. This code is for educational purposes and you can test this code and learn more about Python programming.

MAC is an acronym for Media Access Control address and is a unique identifier assigned to network interfaces (e.g: NIC cards) for communications at the data link layer of a network segment.

There is the source code of the generator:
`#!/usr/bin/python
# *-* coding:utf-8 *-*

import random

def randomMAC():
”’
generate random MAC address.
the first 24 bits are for OUI (Organizationally Unique Identifier).
”’
mac = [0x00, 0x8c, 0xfa,
random.randint(0x00, 0xff),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff)
] return ‘:’.join(map(lambda x: “%02x” % x, mac))

if __name__ == ‘__main__’:
print randomMAC()`

I hope this code will be helpful to you, if you have some questions then ask me in the comments.

Share with Friends
FacebookTwitterGoogle+LinkedInEmail
Use Cybytes and
Tip the Author!
Join
Share with Friends
FacebookTwitterGoogle+LinkedInEmail
Ready to share your knowledge and expertise?
7 Comments
  1. Hi Bmsr256, what is this the benefit for your script against macchanger ?

    • Hi, the purpose of this code is to help you understand in python how do you can change a MAC address via software, like macchanger, however macchanger is a very powerful tool and available in many Unix/Linux platforms. This code is to help you understand how things work.

  2. testing…
    thank you

Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play
 

Support Cybrary

Donate Here to Get This Month's Donor Badge

 
Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel