Skip to content

Instantly share code, notes, and snippets.

@tyr0chen
Created February 20, 2015 13:09
Show Gist options
  • Save tyr0chen/6a137a6e645af0236797 to your computer and use it in GitHub Desktop.
Save tyr0chen/6a137a6e645af0236797 to your computer and use it in GitHub Desktop.
generet random legel mac address
#!/bin/bash
#Description:this program automatically generates random legal mac address
#Ver.2.0 2014-10-26
#Author:Tyr
#Usage:./random_mac.sh [num]
i=0
while [ "$i" -lt "$1" ]
do
random=$(hexdump -n6 -e '/1 ":%02x"' /dev/urandom)
if echo $random | grep -q '*';then
continue
fi
octet=`echo $random | cut -d : -f2`
shi=$((0x${octet}))
flag=$(($shi%2))
if [ $flag -eq 0 ];then
mac=`echo $random | sed 's/^://g'`
echo $mac
i=$((i+1))
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment