Last active
November 30, 2017 13:46
-
-
Save korc/a847ff5d9517d457d2d15c851c865660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Changes WiFi NIC MAC address to MD5-based semi-random value | |
name="$1" | |
iface="$2" | |
: "${ifaces:=$(for i in /sys/class/net/*;do test ! -d $i/wireless || { echo -n "$_s${i##*/}";_s=" ";};done)}" | |
: "${iface:=$(echo "$ifaces" | cut -f1 -d" ")}" | |
test -n "$iface" || { | |
echo "ERROR: cannot find interface" >&2 | |
test -z "$name" || exit 1 | |
} | |
test -n "$name" || { | |
echo "Usage: ${0##*/} <name> [<iface=$iface>]" >&2 | |
echo "Available interaces: $ifaces" >&2 | |
exit 1 | |
} | |
name2mac() { | |
local name="$1" new_mac octet | |
for octet in $(echo -n "$name" | md5sum | fold -w2 | head -6);do | |
if test -z "$new_mac";then | |
new_mac="$(printf "%02x" $((0x$octet&0xfe|2)))" | |
else | |
new_mac="$new_mac:$octet" | |
fi | |
done | |
echo "$new_mac" | |
} | |
new_mac="$(name2mac "$name")" | |
set -xe | |
ip link set "$iface" address "$new_mac" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment