MAC Address Changer is a Python script that allows you to modify the MAC address of a specified network interface on supported Unix-based systems.
The script can:
- Change to a custom MAC address
- Generate and assign a random MAC address
- Validate MAC address format
- Ensure root privileges before execution
- Detect supported operating systems
- Python 3.x
- Root privileges (sudo)
- Unix-based operating system:
- Linux
- macOS (Darwin)
The script relies on the ifconfig command to update the MAC address.
The script supports:
- linux
- linux2
- darwin
If run on an unsupported operating system, it will return an error.
Run the script using sudo:
sudo python3 script.py --iface=<Network Interface> <--mac=<MAC> OR --random=True>| Argument | Description |
|---|---|
| --iface | Network interface (e.g., eth0, wlan0, en0) |
| --mac | 12-digit MAC address (without colons) |
| --random | Generate a random MAC address |
Note: Use only one of --mac or --random.
sudo python3 script.py --iface=eth0 --mac=001122AABBCCThe script will format the MAC as:
00:11:22:AA:BB:CC
sudo python3 script.py --iface=eth0 --random=TrueThis generates a 12-character hexadecimal MAC address automatically.
The script ensures:
- Exactly 12 hexadecimal characters
- Allowed characters:
- 0–9
- A–F
- a–f
If invalid, you will see:
[x] mac addrress not valid .
The script must be executed as root:
sudo python3 script.py ...If not run as root:
[x] use script as root .
- Detects operating system
- Checks root privileges
- Parses command-line arguments
- Validates MAC address
- Brings interface down
- Changes MAC address
- Brings interface back up
Internally executes:
ifconfig <iface> down
ifconfig <iface> hw ether <mac>
ifconfig <iface> upThe script will display usage instructions if:
- Required arguments are missing
- Invalid arguments are provided
- MAC address format is incorrect
- OS is unsupported
- Root privileges are missing
class changeMacAddressKey methods:
- detectOs()
- hasRootPrivilege()
- parseArgs()
- parseMacAddress()
- isValideMAc()
- randomMacAddress()
- changeMacAddress()
- usage()
Changing your MAC address may:
- Temporarily disconnect your network
- Violate certain network policies
Use responsibly and only on networks you are authorized to modify.
Provided as-is for educational and testing purposes.