James Roseman
James Roseman

Reputation: 1624

MAC changing program or daemon?

I'm currently have a program which creates a list of all MAC addresses and corresponding names and IP addresses on my network.

I was wondering if it's possible (theoretically) to create a background program which, every hour, would change your MAC address based on the list you provide. The list would continuously be updated by the already stated program.

I'm good with Python and Batch, but I'm running a Mac system right now (which is what I want to implement this program on) and have little knowledge of bash when it comes to the network itself, or of creating background tasks that are time sensitive.

If this is too broad of a question, please do let me know.

Thank you!

Upvotes: 0

Views: 281

Answers (1)

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137438

You could accomplish this with a simple script, and periodically run it using cron.

Here is an example of how to change your MAC address from a shell script (adapted from here)

#NETWORKING="/etc/init.d/networking"   # On some systems
NETWORKING="service network"           # On my Fedora 16 box

$NETWORKING stop
ifconfig eth0 hw ether 02:01:02:03:04:08
$NETWORKING start

So you'd need to come up with a way to randomize that MAC address.

Then, use crontab -e to add it to your crontab. Here is a quick reference for crontab.

Here's some python to generate a random MAC address and change it. Only the MAC generation has been tested (for obvious reasons). Also note, you may want to limit the range on some of the bytes in the MAC address, but that is outside the scope of my answer.

from subprocess import call
import random

mac = [random.randint(0, 0xFF) for i in range(6)]    
macstr = ':'.join(['{:02X}'.format(x) for x in mac])
print 'Changing MAC address to', macstr

call(['service', 'network', 'stop')
call(['ifconfig', 'eth0', 'hw', 'ether', macstr])
call(['service', 'network', 'start')

Upvotes: 1

Related Questions