-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchmac
More file actions
executable file
·97 lines (84 loc) · 1.76 KB
/
Copy pathchmac
File metadata and controls
executable file
·97 lines (84 loc) · 1.76 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
#
# 20081116 Brandon Pierce <brandon@ihashacks.com>
#
# Increments to the next valid MAC address for an interface,
# looping through all possible MAC addresses.
#
# History:
#
# -20081116 - Initial release
# -20081123 -
IF=eth1
DEFMAC="00:15:00:1d:ca:ca"
usage()
{
echo "Usage: `basename $0` [-i <interface>] [-m <mac address>] [-v verbose]"
echo -e "\t\t [-d default]"
exit 1
}
if [ ${#@} -eq 0 ]; then
usage
fi
default()
{
echo "Setting mac address for $IF to default of $DEFMAC"
sudo /sbin/ifconfig $IF hw ether $DEFMAC
exit 0
}
manual()
{
echo "Manually setting mac address for $IF to $MAC"
sudo /sbin/ifconfig $IF hw ether $MAC
exit 0
}
random()
{
echo "Random feature not yet implemented"
exit 1
}
setintf()
{
echo "Setting interface to $IF"
#IF="$OPTARG"
}
while getopts im:hvdr o
do case "$o" in
i) IF="$OPTARG" && setintf;;
m) MAC="$OPTARG" && manual;;
h) usage;;
v) set -x;;
d) default;;
r) random;;
esac
done
#
# Use all but the last subscript of our current MAC to define our prefix
# Set the last subscript to be our current MAC suffix
#
MACPFX=`/sbin/ifconfig $IF | grep HWaddr | awk ' { print $5 } ' | cut -c 1-14`
MACSFX=`/sbin/ifconfig $IF | grep HWaddr | awk ' { print $5 } ' | \
awk -F: ' { print $6 } '`
#
# Convert our current MAC suffix to base 10 for incrementing
#
DECSFX=`printf "%d\n" 0x$MACSFX`
#
# Increment the decimal value by 1 unless the total will exced 0xff,
# otherwise it will reset to 1
#
if [ $(($DECSFX+1)) -lt "256" ]; then
DECSFX=$(($DECSFX+1));
else
DECSFX=1;
fi
#
# Convert our new suffix to base 16
#
NEWSFX=`printf "%02X\n" $DECSFX`
#
# Concatenate variables and update the interface
#
NEWMAC=`echo $MACPFX:$NEWSFX`
echo "Setting mac address for $IF to $NEWMAC"
sudo /sbin/ifconfig $IF hw ether $NEWMAC