/[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 716 - (hide annotations) (download)
Tue Nov 23 18:41:01 2004 UTC (13 years, 1 month ago) by uberlord
Original Path: trunk/net-scripts/net.modules.d/macchanger
File size: 2470 byte(s)
fixed variables for vlans in most modules

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20