Here is my approach which I'm using (on ROS 7.16.2):
:local randBssid do={
:local macOctets [:toarray ""]
:local oct ""
:for i from=0 to=[:len $bssid] do={
:local chr [:pick $bssid $i ($i + 1)]
:if ($chr = $macDelimiter) do={
:set macOctets ($macOctets, $oct)
:set oct ""
} else={:set oct "$oct$chr"}
}
:set macOctets ($macOctets, $oct)
:if ([:len $macOctets] != 6) do={
:return ""
}
:foreach i in={1;2;3} do={
:set ($macOctets->$i) [:rndstr from="123456789ABCDE" length=2]
}
:return [:serialize $macOctets delimiter=$macDelimiter to=dsv]
}
:global bssidRandomizerRunning
:if (!$bssidRandomizerRunning) do={
:set bssidRandomizerRunning true
:local bssids [:toarray ""]
:local macDelimiter ":"
:local maxIterations 100
/interface/wifi
:foreach i in=[find disabled=no] do={
:local bssid [get $i mac-address]
:local rBssid ""
:local count 0
:local found false
:do {
:set rBssid [$randBssid bssid=$bssid macDelimiter=$macDelimiter]
:set count ($count + 1)
:set found false
:if ($rBssid != "") do={
:foreach b in=$bssids do={
:if (!$found && $b = $rBssid) do={:set found true}
}
}
} while=($found && $count < $maxIterations)
:if ($rBssid != "" && $count < $maxIterations) do={
:set bssids ($bssids, $rBssid)
set $i mac-address=$rBssid
} else={
:local ifName [get $i name]
:if ($count = $maxIterations) do={
:log warn "Unable to generate unique random MAC address (BSSID) for wifi interface '$ifName', max iterations reached (bug?), skipping..."
} else={
:log warn "Unable to parse MAC address (BSSID) '$bssid' set on wifi interface '$ifName', skipping..."
}
}
}
:set bssidRandomizerRunning
}
and yes,
[$num2hex] can be raplaced with
[:rndstr from="123456789ABCDE" length=2]) as @rextended suggested above, will change that...
It randomizes 2-4 octets (
:foreach i in={1;2;3} do={...) from current wifi mac address (BSSID) and ensures that all new generated macs are unique, last 2 octets I'm using for personal tracking, it can be easily changed which octets to randomize in mentioned
:foreach loop.
Added 2 schedulers to execute this script, on startup (with 5s delay before script execution) and each day at night time.
Edit: updated script with
[:rndstr ...] to generate random octet.
Edit2: removed wifi enabled status toggle on bssid change