I need to generate in bash random mac addresses without using macchanger or similar.
I have this:
random_mac=$(hexdump -n6 -e '/1 ":%02X"' /dev/random | sed s/^://g)
But with this sometimes, if you try to put the mac into the interace it says SIOCSIFHWADDR: Cannot assign requested address. I investigated about this and it seems something related to unicast addresses. I have a workaround working:
random_mac=00:$(cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 200 | md5sum | sed -r 's/^(.{10}).*$/\1/;s/([0-9a-f]{2})/\1:/g; s/:$//;')
But I don't like too much this because is not completely random. It has always 00 at the beginning.
Any known bash random mac generator fitting the unicast rule?
I read other methods using od. I'm trying to use as less tools as possible in order to have less requeriments to run the script. Can be done without od? or is od absolutely always included in all Linux distros? If yes, I can use it.
Aucun commentaire:
Enregistrer un commentaire