No Account Yet?

You are not logged in.

Add to: JBookmarks Add to: Facebook Add to: Windows Live Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Blogmarks Add to: Technorati Add to: Newsvine Add to: Google Information
Generate MAC addresses for XEN using shell E-mail
Programming HowTo's - Shell HowTo's
Written by Christopher Hahn   
Monday, 28 April 2008 11:09

#!/bin/bash
# Generate unique valid XEN MAC addresses in shell, 'cause it's faster ;)
# Xen MAC's begin with 00:16:3e

declare -i num="${1:-0}"
until [[ $num -gt 0 ]]; do
read -p "How many MAC's do you want to generate? " num
done

declare -a macs=( )

while [[ $num -gt 0 ]]; do
mac=$(printf '%02x:%02x:%02x' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256)))

for i in "${macs[@]}"; do
[[ $mac = $i ]] && continue 2
done

macs[${#macs[*]}]=$mac
echo 00:16:3e:$mac
num=$((num-1))
done

Comments
Search RSS
Only registered users can write comments!

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Monday, 28 April 2008 20:45 )