/[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 535 - (show annotations) (download)
Thu Aug 12 22:10:30 2004 UTC (14 years ago) by agriffis
Original Path: trunk/net-scripts/net.modules.d/macchanger
File size: 2483 byte(s)
- changes from UberLord, in particular before/after dep processing

1 # macchanger module for net-scripts
2 # Copyright 2004 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # Contributed by Roy "UberLord" Marples <uberlord@rsm.demon.co.uk>
5 # $Header$
6 #
7 # Based on code from Gentoo Linux /etc/init.d/net.eth0 version 1.45
8
9 # char* macchanger_provides(void)
10 #
11 # Returns a string to change module definition for starting up
12 macchanger_provides() {
13 echo "macchanger"
14 }
15
16 # char* macchanger_before(void)
17 #
18 # Returns a space seperated array of modules this module should be loaded before
19 macchanger_before() {
20 echo "interface"
21 }
22
23 # bool macchanger_check_installed(void)
24 #
25 # Returns 1 if macchanger is installed, otherwise 0
26 macchanger_check_installed() {
27 [[ -x /sbin/macchanger ]] && return 0
28 [[ true == ${1} ]] && eerror "For changing MAC addresses, emerge net-analyzer/macchanger"
29 return 1
30 }
31
32 # bool macchanger_check_depends(void)
33 #
34 # Checks to see if we have the necessary package installed
35 # and the handler supports the necessary functionality
36 macchanger_check_depends() {
37 local e
38
39 [[ -z ${e} && function != $( type -t interface_get_mac_address ) ]] && e=interface_get_mac_address
40 [[ -z ${e} ]] && return 0
41
42 eerror "macchanger: interface is missing the required function ${e}\n"
43 return 1
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
51
52 eval mac=\"\$\{mac_${iface}\}\"
53 [[ -z ${mac} ]] && return 0
54
55 case "${mac}" in
56 # specific mac-addr, i wish there were a shorter way to specify this
57 [0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]:[0-9a-zA-Z][0-9a-zA-Z]) opts="${opts} --mac=${mac}" ;;
58
59 # increment MAC address, default macchanger behavior
60 increment) opts="${opts}" ;;
61
62 # randomize just the ending bytes
63 random-ending) opts="${opts} -e" ;;
64
65 # keep the same kind of physical layer (eg fibre, copper)
66 random-samekind) opts="${opts} -a" ;;
67
68 # randomize to any known vendor of any physical layer type
69 random-anykind) opts="${opts} -A" ;;
70
71 # fully random bytes
72 random-full) opts="${opts} -r" ;;
73
74 # default case is just to pass on all the options
75 *) opts="${opts} ${mac}" ;;
76 esac
77
78 e=$( /sbin/macchanger ${opts} ${IFACE} )
79 if [[ -n ${e} ]]; then
80 eerror "Failed to set MAC address"
81 return 1
82 fi
83
84 mac=$( interface_get_mac_address ${iface} )
85 einfo " MAC address for ${iface} changed to ${mac}"
86
87 return 0 #important
88 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20