/[baselayout]/trunk/net/macchanger.sh
Gentoo

Contents of /trunk/net/macchanger.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2567 - (show annotations) (download) (as text)
Tue Apr 10 10:33:44 2007 UTC (7 years, 4 months ago) by uberlord
File MIME type: text/x-sh
File size: 2118 byte(s)
Misc network fixes so we work on my stable server. Splash plugin removed as splashtuils-1.4 now ships with its own.
1 # Copyright 2004-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 macchanger_depend() {
5 before macnet
6 }
7
8 _config_vars="$_config_vars mac"
9
10 macchanger_pre_start() {
11 # We don't change MAC addresses from background
12 ${IN_BACKGROUND} && return 0
13
14 local mac= opts=
15
16 eval mac=\$mac_${IFVAR}
17 [ -z "${mac}" ] && return 0
18
19 _exists true || return 1
20
21 ebegin "Changing MAC address of ${IFACE}"
22
23 # The interface needs to be up for macchanger to work most of the time
24 _down
25
26 mac=$(echo "${mac}" | tr '[:upper:]' '[:lower:]')
27 case "${mac}" in
28 # specific mac-addr, i wish there were a shorter way to specify this
29 [0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f])
30 # We don't need macchanger to change to a specific mac address
31 _set_mac_address "${mac}"
32 if eend "$?" ; then
33 mac=$(_get_mac_address)
34 eindent
35 einfo "changed to ${mac}"
36 eoutdent
37 _up
38 return 0
39 fi
40 ;;
41
42 # increment MAC address, default macchanger behavior
43 increment) opts="${opts}" ;;
44
45 # randomize just the ending bytes
46 random-ending) opts="${opts} -e" ;;
47
48 # keep the same kind of physical layer (eg fibre, copper)
49 random-samekind) opts="${opts} -a" ;;
50
51 # randomize to any known vendor of any physical layer type
52 random-anykind) opts="${opts} -A" ;;
53
54 # fully random bytes
55 random-full|random) opts="${opts} -r" ;;
56
57 # default case is just to pass on all the options
58 *) opts="${opts} ${mac}" ;;
59 esac
60
61 if [ ! -x /sbin/macchanger ] ; then
62 eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
63 return 1
64 fi
65
66 mac=$(/sbin/macchanger ${opts} "${IFACE}" \
67 | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' )
68 _up
69
70 # Sometimes the interface needs to be up ....
71 if [ -z "${mac}" ] ; then
72 mac=$(/sbin/macchanger ${opts} "${IFACE}" \
73 | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' )
74 fi
75
76 if [ -z "${mac}" ] ; then
77 eend 1 "Failed to set MAC address"
78 return 1
79 fi
80
81 eend 0
82 eindent
83 einfo "changed to" "${mac}"
84 eoutdent
85
86 return 0
87 }
88
89 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20