/[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 - (show annotations) (download)
Tue Nov 23 18:41:01 2004 UTC (12 years, 10 months 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 # macchanger module for net-scripts
2 # Version 1.0.2
3 # Copyright (c) 2004 Gentoo Foundation
4 # Distributed under the terms of the GNU General Public License V2
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 need interface
20 }
21
22 # 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 ${1:-false} && eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
28 return 1
29 }
30
31 # bool macchanger_check_depends(void)
32 #
33 # Checks to see if we have the needed functions
34 macchanger_check_depends() {
35 local f
36
37 for f in interface_get_mac_address; do
38 [[ $( type -t ${f} ) == function ]] && continue
39 eerror "macchanger: missing required function ${f}\n"
40 return 1
41 done
42
43 return 0
44 }
45
46 # bool macchanger_pre_start(char *iface)
47 #
48 # Configures the MAC address for iface
49 macchanger_pre_start() {
50 local iface=${1} mac opts e old_mac new_mac
51 local ifvar=$( interface_variable ${1} )
52
53 eval mac=\"\$\{mac_${ifvar}\}\"
54 [[ -z ${mac} ]] && return 0
55
56 mac=$( echo ${mac} | tr '[:lower:]' '[:upper:]' )
57 case "${mac}" in
58 # specific mac-addr, i wish there were a shorter way to specify this
59 [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
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 # 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 return 1
88 fi
89
90 eend 0
91 eindent
92 einfo "changed to ${mac}"
93 eoutdent
94
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