/[baselayout]/branches/rc-scripts-1_6/net-scripts/net.modules.d/macchanger
Gentoo

Contents of /branches/rc-scripts-1_6/net-scripts/net.modules.d/macchanger

Parent Directory Parent Directory | Revision Log Revision Log


Revision 869 - (show annotations) (download)
Tue Jan 25 10:42:54 2005 UTC (12 years, 8 months ago) by uberlord
File size: 2708 byte(s)
Updated copyright headers

1 # Copyright (c) 2004-2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header$
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # char* macchanger_provides(void)
8 #
9 # Returns a string to change module definition for starting up
10 macchanger_provides() {
11 echo "macchanger"
12 }
13
14 # void macchanger_depend(void)
15 #
16 # Sets up the dependancies for the module
17 macchanger_depend() {
18 before interface wireless
19 }
20
21 # bool macchanger_check_installed(void)
22 #
23 # Returns 1 if macchanger is installed, otherwise 0
24 macchanger_check_installed() {
25 [[ -x /sbin/macchanger ]] && return 0
26 ${1:-false} && eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
27 return 1
28 }
29
30 # bool macchanger_check_depends(void)
31 #
32 # Checks to see if we have the needed functions
33 macchanger_check_depends() {
34 local f
35
36 for f in interface_variable interface_get_mac_address; do
37 [[ $( type -t ${f} ) == function ]] && continue
38 eerror "macchanger: missing required function ${f}\n"
39 return 1
40 done
41
42 return 0
43 }
44
45 # bool macchanger_pre_start(char *iface)
46 #
47 # Configures the MAC address for iface
48 macchanger_pre_start() {
49 local iface=${1} mac opts
50 local ifvar=$( interface_variable ${1} )
51
52 eval mac=\"\$\{mac_${ifvar}\}\"
53 [[ -z ${mac} ]] && return 0
54
55 interface_exists ${iface} true || return 1
56
57 mac=$( echo ${mac} | tr '[:upper:]' '[:lower:]' )
58 case "${mac}" in
59 # specific mac-addr, i wish there were a shorter way to specify this
60 [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]) opts="${opts} --mac=${mac}" ;;
61
62 # increment MAC address, default macchanger behavior
63 increment) opts="${opts}" ;;
64
65 # randomize just the ending bytes
66 random-ending) opts="${opts} -e" ;;
67
68 # keep the same kind of physical layer (eg fibre, copper)
69 random-samekind) opts="${opts} -a" ;;
70
71 # randomize to any known vendor of any physical layer type
72 random-anykind) opts="${opts} -A" ;;
73
74 # fully random bytes
75 random-full) opts="${opts} -r" ;;
76
77 # default case is just to pass on all the options
78 *) opts="${opts} ${mac}" ;;
79 esac
80
81 # The interface needs to be up for macchanger to work most of the time
82 interface_down ${iface}
83
84 ebegin "Changing MAC address of ${iface}"
85 mac=$( /sbin/macchanger ${opts} ${iface} 2>/dev/null | awk '/Faked MAC:/ { print toupper($3) }' )
86
87 # Sometimes the interface needs to be up ....
88 if [[ -z ${mac} ]]; then
89 interface_up ${iface}
90 mac=$( /sbin/macchanger ${opts} ${iface} 2>/dev/null | awk '/Faked MAC:/ { print toupper($3) }' )
91 fi
92
93 if [[ -z ${mac} ]]; then
94 eend 1 "Failed to set MAC address"
95 return 1
96 fi
97
98 eend 0
99 eindent
100 einfo "changed to ${mac}"
101 eoutdent
102
103 return 0 #important
104 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20