etc/functions: Add a function to generate random MAC address

This commit is contained in:
Thierry Laurion 2022-04-29 10:24:02 -04:00
parent fb5cfd5cc2
commit 37a343a49c
No known key found for this signature in database
GPG Key ID: E7B4A71658E36A93

View File

@ -374,3 +374,9 @@ print_battery_charge()
echo "$battery_charge"
fi
}
generate_random_mac_address()
{
#Borrowed from https://stackoverflow.com/questions/42660218/bash-generate-random-mac-address-unicast
hexdump -n 6 -ve '1/1 "%.2x "' /dev/urandom | awk -v a="2,6,a,e" -v r="$RANDOM" 'BEGIN{srand(r);}NR==1{split(a,b,",");r=int(rand()*4+1);printf "%s%s:%s:%s:%s:%s:%s\n",substr($1,0,1),b[r],$2,$3,$4,$5,$6}'
}