mirror of
https://github.com/linuxboot/heads.git
synced 2025-01-18 10:46:44 +00:00
Merge pull request #1160 from tlaurion/gen_mac_address_for_maximized_boards
Add Heads mac address randomization for maximized boards
This commit is contained in:
commit
46d64e9f16
@ -1,5 +1,7 @@
|
||||
#!/bin/ash
|
||||
|
||||
. /etc/functions
|
||||
|
||||
# bring up the ethernet; maybe should do DHCP?
|
||||
ifconfig lo 127.0.0.1
|
||||
|
||||
@ -11,6 +13,16 @@ for module in `echo $network_modules`; do
|
||||
done
|
||||
|
||||
if [ -e /sys/class/net/eth0 ]; then
|
||||
#Randomize eth0 MAC address of maximized boards
|
||||
if echo "$CONFIG_BOARD" | grep -q maximized; then
|
||||
ifconfig eth0 down
|
||||
echo "Generating random MAC address (might take a while)..."
|
||||
mac=$(generate_random_mac_address)
|
||||
echo "Assigning randomly generated MAC: $mac to eth0..."
|
||||
ifconfig eth0 hw ether $mac
|
||||
ifconfig eth0 up
|
||||
fi
|
||||
|
||||
# Set up static IP
|
||||
if [ ! -z "$CONFIG_BOOT_STATIC_IP" ]; then
|
||||
ifconfig eth0 $CONFIG_BOOT_STATIC_IP
|
||||
|
@ -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}'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user