#!/usr/bin/ruby
def RandomMac()
hexList =["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
srand();
res ="00"; #assign the first two digits to 00 (this makes it look more legit
for i in (0..4)
res +=":" +hexList[rand(hexList.length)] +hexList[rand(hexList.length)];
end
return res;
end
def Execute(cmd)
output =IO.popen(cmd) { |io| io.read }
return output
end
if(ARGV[0] ==nil)
print("Usage:\n\tmacRan.rb interface\n");
else
Execute("ifconfig " +ARGV[0] +" down");
Execute("ifconfig " +ARGV[0] +" hw ether " +RandomMac());
Execute("ifconfig " +ARGV[0] +" up");
#find the new mac address and then display it to the user
newMac =Execute("ifconfig " +ARGV[0] +" | grep HWaddr").split(" ");
print(newMac[newMac.length-1], "\n");
end