Skip to content

Instantly share code, notes, and snippets.

@mattronix
Created November 4, 2018 18:30
Show Gist options
  • Save mattronix/1f978c5092f6fe97f5cc25a2db5597d5 to your computer and use it in GitHub Desktop.
Save mattronix/1f978c5092f6fe97f5cc25a2db5597d5 to your computer and use it in GitHub Desktop.
#!/bin/sh
# /etc/NetworkManager/dispatcher.d/pre-up.d/randomize-mac-addresses.sh
# Orignal Article:
# See https://www.paulfurley.com/randomize-your-wifi-mac-address-on-ubuntu-1604-xenial/
export PATH=$PATH:/usr/bin:/bin
LOG_FILE=/var/log/randomize-mac-addresses
echo "$(date): $*" > ${LOG_FILE}
WIFI_UUIDS=$(nmcli --fields type,uuid connection show |grep wifi |cut '-d ' -f3)
for UUID in ${WIFI_UUIDS}
do
UUID_DAILY_HASH=$(echo "${UUID}-$(date +%F)" | md5sum)
RANDOM_MAC="02:$(echo -n ${UUID_DAILY_HASH} | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4:\5/')"
CMD="nmcli connection modify ${UUID} wifi.cloned-mac-address ${RANDOM_MAC}"
echo "$CMD" >> ${LOG_FILE}
$CMD &
done
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment