/[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 757 - (show annotations) (download)
Mon Dec 6 15:46:18 2004 UTC (13 years, 10 months ago) by agriffis
File size: 2693 byte(s)
Merge updates from HEAD

1 # macchanger module for net-scripts
2 # Version 1.0.3
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 }
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
50 local ifvar=$( interface_variable ${1} )
51
52 eval mac=\"\$\{mac_${ifvar}\}\"
53 [[ -z ${mac} ]] && return 0
54
55 mac=$( echo ${mac} | tr '[:upper:]' '[:lower:]' )
56 case "${mac}" in
57 # specific mac-addr, i wish there were a shorter way to specify this
58 [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}" ;;
59
60 # increment MAC address, default macchanger behavior
61 increment) opts="${opts}" ;;
62
63 # randomize just the ending bytes
64 random-ending) opts="${opts} -e" ;;
65
66 # keep the same kind of physical layer (eg fibre, copper)
67 random-samekind) opts="${opts} -a" ;;
68
69 # randomize to any known vendor of any physical layer type
70 random-anykind) opts="${opts} -A" ;;
71
72 # fully random bytes
73 random-full) opts="${opts} -r" ;;
74
75 # default case is just to pass on all the options
76 *) opts="${opts} ${mac}" ;;
77 esac
78
79 # The interface needs to be up for macchanger to work most of the time
80 interface_down ${iface}
81
82 ebegin "Changing MAC address of ${iface}"
83 mac=$( /sbin/macchanger ${opts} ${iface} 2>/dev/null | awk '/Faked MAC:/ { print toupper($3) }' )
84
85 # Sometimes the interface needs to be up ....
86 if [[ -z ${mac} ]]; then
87 interface_up ${iface}
88 mac=$( /sbin/macchanger ${opts} ${iface} 2>/dev/null | awk '/Faked MAC:/ { print toupper($3) }' )
89 fi
90
91 if [[ -z ${mac} ]]; then
92 eend 1 "Failed to set MAC address"
93 return 1
94 fi
95
96 eend 0
97 eindent
98 einfo "changed to ${mac}"
99 eoutdent
100
101 return 0 #important
102 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20