randomize-mac 799 Bytes
Newer Older
Felix Eckhofer's avatar
Felix Eckhofer committed
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
#!/bin/sh
# temporarily shut down an interface and randomize the mac,
# requires the macchanger tool.
#
# place in /etc/network/if-post-down.d to renew the mac everytime
# a network interface is brought down (recent versions of
# NetworkManager no longer support if-pre-up.d)
#
# felix@tribut.de

LOGFILE="`mktemp`"
PRESTATE="`ip addr show dev \"$IFACE\" up 2>>\"$LOGFILE\"`"
FAILED="0"

date >> "$LOGFILE"
echo "Running randomize-mac for interface '$IFACE'" >> "$LOGFILE"
echo >> "$LOGFILE"

[ -n "$PRESTATE" ] && ip link set dev "$IFACE" down >>"$LOGFILE" 2>&1
macchanger -A "$IFACE" >>"$LOGFILE" 2>&1 || FAILED=1
[ -n "$PRESTATE" ] && ip link set dev "$IFACE" up >>"$LOGFILE" 2>&1

if [ "$FAILED" = "1" ]; then
	cat "$LOGFILE" | mail -s "[`hostname`] macchanger failed" root
fi

rm -f "$LOGFILE"