MAC address

Heiko Wundram heikowu at
Mon Sep 20 10:05:25 CEST 2004

Am Montag, 20. September 2004 08:51 schrieb Ajay:
> is it possible to change your MAC address from a program?
> Can i do that using Python?

Depends on what OS you're under... Under Linux (and I'd guess that *BSD works 
somewhat similar), you can change the hardware address of some network device 

ifconfig <device> down
ifconfig <device> hw <hw-type> <address>
ifconfig <device> up

So, for example, to change my MAC to some random number (which is invalid, 
because it's a broadcast address):

ifconfig eth0 down
ifconfig eth0 hw ether fffefdfcfbfa
ifconfig eth0 up

Of course, you need to call all this as root.

From Python, that would be:

import os

def setmac(device,mac):
 os.system("ifconfig %s down" % device)
 os.system("ifconfig %s hw ether %s" % (device,mac))
 os.system("ifconfig %s up" % device)

Under Windows (2000, XP, NT?) there's also the possibility to change the MAC 
of a network device, but I don't know if you can access this OS functionality 
from somewhere else than the dialog box which offers it (maybe you can change 
it somewhere in the registry, don't know).


More information about the Python-list mailing list