SCRIPT : mac_address_change.sh *bug?*
Posted: Sun Nov 21, 2021 7:51 pm
This is something I ran into and wanted to report on. Now I'm no programmer so be gentle
I had an issue where an invalid mac address was created. After some troubleshooting I found the mac_address_change.sh. Afaict it does not create universally administered unicast addresses properly. Only x0- x4- x8- xC- are unicast. Which is probably the reason why it wasn't accepted by the NIC. I traced it back to this part of the code:
Now since this is not cryptography I would use /dev/urandom because its faster. The last two bits of the first octet can be shifted to the right, then shifted back. This would skip any multicast or locally administered generated mac addresses.
However the more simple solution would be to change the first octet to 00 which is unicast compliant.
I had an issue where an invalid mac address was created. After some troubleshooting I found the mac_address_change.sh. Afaict it does not create universally administered unicast addresses properly. Only x0- x4- x8- xC- are unicast. Which is probably the reason why it wasn't accepted by the NIC. I traced it back to this part of the code:
Code: Select all
# very rarely the hexdump thing plus bitwise operations fails, so I repeat the MAC address generation to be sure
until echo "${MAC_ADDRESS}" | grep -qE "[0-9A-F]{2}(\:[0-9A-F]{2}){5}"
do
MAC_ADDRESS="$(printf "%012X" $(( 0x$(hexdump -n6 -e '/1 "%02X"' /dev/random) & 0xFEFFFFFFFFFF | 0x020000000000 )) | sed 's/.\{2\}/&:/g' | sed s/:$//g)"
done
Code: Select all
MAC_ADDRESS=`printf '%02x\n' $(( $(( 0x$(hexdump -n1 -e'1/1 "%02X"' /dev/urandom) >> 2 )) << 2 ))`
MAC_ADDRESS=${MAC_ADDRESS}$(hexdump -n5 -e '5/1 ":%02X"' /dev/urandom)
Code: Select all
MAC_ADDRESS="$(hexdump -n5 -e'"00" 5/1 ":%02X"' /dev/urandom)"