What is mac address?

A Mac address or Media access control address is a unique identifier of any device which is assign to network interface control card or NIC card for communication at the data link layer of any network segment. Physical address are most often assigned by the manufacturer of a NIC and are stored in its hardware, such as the card’s read-only memory or some other firmware mechanism

It may also known as Hardware address or physical address of any device which have to communicate in network like as:- Mobile phone, computer, Router, Wi-Fi device etc.

It has 6 octets which is separated by colan(:)  each octets contain 8-bit and total 48-bit of  address space, First three octets specify organizationally unique identifier and last three octets network interface control specific.

Sample mac address image

How to change mac address using python script?


Python is also a very powerful & most important programming language in hacking and security field. However perl and ruby are also very smart and powerful languages. Although There are many tools available in the market which is written in python so here we discuss about to change mac address of Linux Operating system using python script.

Let’s find out the hardware address of our system with ifconfig command.
Changing Physical address using python script.

1. #!/usr/bin/env python
2. import subprocess
3. interface = raw_input(“Interface > “)
4. new_mac = raw_input(“New MAC > “)
5. subprocess.call([“ifconfig”, interface, “down”])
6. subprocess.call([“ifconfig”, interface, “hw”, “ether”, new_mac])
7. subprocess.call([“ifconfig”, interface, “up”]) 

This will change the mac address of your Linux operating system.

Understanding pyhton script for mac changing

In this script first line is for syntax to write a python script in Linux OS. Second line we import a library called subprocess which contains commands of Linux operating system. Third & fourth line will take the input from the user and store in the variable interface &  new_mac respectively. Last three lines are used to calling the function called call which contains Linux commands. Above all code will change mac address of linux operating system. Let’s run this script, we can see finally our hardware address is change.

Categories: Uncategorised

1 Comment

MAC Address changing script by bash shell - Cybrary india · 24th November 2018 at 11:18 pm

[…] you can change mac using python script. if you want to learn how to change mac using python, so you can refer another blog which is on […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: