How to Change the MAC ID(Without any external software)

Hey Guys! Today we are here with a python program which can change the mac id of the network interface the user .

A MAC address is a unique identifier assigned to a network interface controller for use as a network address in communications within a network segment. This use is common in most IEEE 802 networking technologies, including Ethernet, Wi-Fi, and Bluetooth.

Yes, the MAC address is unique, buy hey we are here to show you a python program to change the mac id of your network interface.

So lets get into the coding session.

Check out our video if you want some "visual experience".



Code :

Let's look at the code and I'll explain it.

import subprocess

interface = input('Enter Interface >> ')
new_mac = input('Enter new MAC >> ')

print('[+] Changing the MAC of' + interface + ' to ' + new_mac)

subprocess.call(['ifconfig',interface,'down'])
subprocess.call(['ifconfig',interface,'hw','ether',new_mac])
subprocess.call(['ifconfig',interface,'up'])

  • So Now on to what this Code does
In this program we are importing a module called subprocess.

Subprocess allows you to enter terminal / system commands.

Then we declared a variable called interface to store the interface name the user want to change the mac of.

Then a new_mac variable to store the new mac address which the user enters.

Then we are printing a message back to the user to indicate the mac is changed and there are no errors.

Then to the actual part of this program.

The first subprocess.call() what that line of code actually does is it passes a command to the terminal "ifconfig interface down" what it actually does is

> It searches for all the drivers and check if there is any driver called "interface"(which the user enters) and shuts it down

The second subprocess.call() is where we actually changes the mac of that interface

> The command passed into the terminal is "ifconfig "interface" hw ether "new_mac""

The third subprocess.call() brings back the interface on.

>The command passed on to the terminal is "ifconfig "interface" up"



Post a Comment

0 Comments