-
-
Save vitalk/0d668cf67f81326c6a87 to your computer and use it in GitHub Desktop.
Returns the unique and valid MAC address in format 00:16:3E:xx:xx:xx.
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
#!/usr/bin/env bash | |
# | |
#: usage: mac <string> | |
#: | |
#: Returns the unique and valid MAC address in format 00:16:3E:xx:xx:xx. | |
#: The <string> uses to create an unique part of the address. | |
function help() { | |
sed -En 's/^#:[[:space:]]?//p' $0 | |
} | |
function hex() { | |
local unique=$1 || $(hostname -f 2>/dev/null) | |
echo 00163e$(echo $unique | md5) | |
} | |
function mac() { | |
echo $(hex $1) | sed -e 's/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\).*/\1:\2:\3:\4:\5:\6/' | |
} | |
if [[ $# -ne 1 ]]; then | |
help && exit; | |
fi | |
mac "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment