-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacgen.sh
More file actions
executable file
·33 lines (23 loc) · 856 Bytes
/
macgen.sh
File metadata and controls
executable file
·33 lines (23 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Generates single MAC address.
# MAC-addresses are generated continuosly.
# Written by Dmitry A. Fedorov <[email protected]>, Sigrand LLC <http://sigrand.ru>, Novosibirsk
# Derived from kdbmacgen.sh by Kazantsev A.V., Sigrand, Novosibirsk, [email protected]
showerr()
{
echo "$@"
exit 1
}
[ -z $1 ] && showerr "Usage: $0 maccounter_file"
MACCOUNTER=$1
# check files permissions
[ -r $MACCOUNTER -a -w $MACCOUNTER ] || showerr "Unable to read or write mac counter file $MACCOUNTER"
# read current MAC counter
curmac=$(cat $MACCOUNTER)
curmachex=$(printf "%.12x" $curmac)
# update mac counter
curmac=$(($curmac + 1))
echo $curmac > $MACCOUNTER
# /bin/bash required due to line below:
mac_formatted=${curmachex:0:2}:${curmachex:2:2}:${curmachex:4:2}:${curmachex:6:2}:${curmachex:8:2}:${curmachex:10:2}
echo $mac_formatted