From 37a343a49cbc30f65b2f3b139dd306c6de3acdd6 Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Fri, 29 Apr 2022 10:24:02 -0400 Subject: [PATCH] etc/functions: Add a function to generate random MAC address --- initrd/etc/functions | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/initrd/etc/functions b/initrd/etc/functions index 45f893b9..b134da9c 100755 --- a/initrd/etc/functions +++ b/initrd/etc/functions @@ -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}' +}