Sitemap
Press enter or click to view image in full size

Programming a MAC Changer in Python

Increase your anonymity by changing your MAC

3 min readJun 12, 2021

In this blog, I am gonna tell you, how you can program a MAC Address changer using Python. So let’s get started.
First thing first, what are the ingredients you gonna need:
1. Virtual Box
2. Kali Linux Image
3. Pycharm
That’s all. I have gone through how to install Kali Linux on Virtual Box and how to write your first python code in Pycharm in a separate blog.

After everything is set up, let's now understand what is actually MAC.

MAC -> Media Access Control
-
Permanent
- Physical
- Unique
- Assigned by the manufacturer

How to check, what’s your device MAC Address
Open a terminal -> type ifconfig

Press enter or click to view image in full size

Why Change the MAC Address?
-
Increases anonymity
- Impersonate other devices
- Bypass filters

Get Rajat Kaushik’s stories in your inbox

Join Medium for free to get updates from this writer.

Now let us see, how we can change MAC Address using the terminal first

Commands to change MAC Address using terminal
  • First, you check what’s your MAC Address using ifconfig
  • Then you shut down your interface
  • Then you enter your desired MAC Address
  • Then you start the interface again

Running Shell command using python module, subprocess

  • The subprocess module contains a number of functions.
  • These functions allow us to execute system commands.
  • Commands depend on the Operating System which executes the script.

MAC Changer Using 3 simple commands

  • First, we shut down the interface
  • Then we change the MAC Address
  • Finally, we restart the interface

Now, let’s execute it using an algorithm
Goal → Check if MAC address was changed

  • Execute and read ifconfig
  • Read the MAC Address from the output
  • Check if MAC in ifconfig is what the user requested
  • Print appropriate message.

Step1: Execute and Read ifconfig

Step2: Read the MAC Address from the output

Step3: Check the result and print the appropriate message.

Output

  • Run python3 mac_changer.py — help to see the manual
Press enter or click to view image in full size
  • Changing MAC Address to 00:22:33:44:55:66
Press enter or click to view image in full size
  • Confirming the change
Press enter or click to view image in full size

That’s all for this blog. The code is available here.

--

--

Rajat Kaushik
Rajat Kaushik

Written by Rajat Kaushik

0 followers

Ethical Hacking Enthusiast | SIH 2020 Winner