# Generate random-ish MAC address
# Tested on RouterOS v5.7
{
# if firewall rules can't be found, add them
if ( [ :len [ /ip firewall filter find comment~"fwrnum" ] ] = 0 ) do={
:for i from=1 to=12 do={
/ip firewall filter add action=passthrough chain=input random="$i" comment="fwrnum$i";
}
}
# MAC characters array
:local macTable A,B,C,D,E,F,0,1,2,3,4,5,6,7,8,9
# length of MacTable array
:local macTableLen [ :len $macTable ];
# variable that will hold our mac address
:local mac;
# generate 12 mac address characters
:for i from=1 to=12 do={
# get packet number from each firewall rule
:local v [/ip firewall filter get [find comment="fwrnum$i"] packets ];
# add $i*$i value to $v
:set v ( $v + ( $i * $i ) );
# add time values, last value of minutes, and both seconds values
:local t ( [ :pick [/system clock get time] 4 5 ] . [ :pick [/system clock get time] 6 8 ] );
# reverse values, increasing frequency of first number change
:set t ( [ :pick $t 2 ] . [ :pick $t 1 ] . [ :pick $t 0 ] );
# add time seed to $v
:set v ( $v + $t );
# if packet number is greater than 100, just grab last 2 digits, as they change most frequently
if ( $v >= 100 ) do={
:set v [ :pick $v ( [ :len $v ] - 2 ) [ :len $v ] ];
}
# reverse the two digits, increasing frequency of variable change
:set v ( [ :pick $v 1 ] . [ :pick $v 0 ] );
# while the value is greater than or equal to the length of the macTable array
while ( $v >= $macTableLen ) do={
# subtract 15, one less than macTable length, so as to create a rainbow effect so to speak
:set v ( $v - 15 );
}
# create mac starting at the end, get mac char from macTable based on our value
:set mac ( [ :pick $macTable $v ] . $mac );
# add mac address colons at appropriate spots
if ($i = 2 || $i = 4 || $i = 6 || $i = 8 || $i = 10) do={
:set mac ( ":" . $mac );
}
}
# remove firewall rules
/ip firewall filter remove [ find comment~"fwrnum" ];
# show mac address
:put $mac;
}