Mutating your MAC address

Recently I was at an airport that offered free WiFi for the first 15 minutes, afterwards the system asked you pay. I knew that they must be checking identity via MAC address, so I wrote this little nifty python script that changes it to some random value each time you call it. This would only work on Linux (or maybe a MAC) OS.
I am not suggesting that you violate any laws, I put this up for educational purposes. Use it at your own risk.
For obtaining the MAC address through python, I used synthesizerpatel‘s code snippet. Alternatively the MAC address could have been obtained via a system call ifconfig using “subprocess.Popen”, as described in here.

 import fcntl, socket, struct, random  
 from subprocess import call  
 def getHwAddr(ifname):  
   s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  
   info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))  
   return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]  
 print "Changing from "+a+" to "+b  
 call(["sudo ifconfig wlan0 down"],shell=True)  
 call(["sudo ifconfig wlan0 hw ether "+b],shell=True)  
 call(["sudo ifconfig wlan0 up"],shell=True)  

Leave a Reply

Your email address will not be published. Required fields are marked *

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