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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 756 Revision 757
1# macchanger module for net-scripts 1# macchanger module for net-scripts
2# Version 1.0.2 2# Version 1.0.3
3# Copyright (c) 2004 Gentoo Foundation 3# Copyright (c) 2004 Gentoo Foundation
4# Distributed under the terms of the GNU General Public License V2 4# Distributed under the terms of the GNU General Public License V2
5# Contributed by Roy Marples (uberlord@gentoo.org) 5# Contributed by Roy Marples (uberlord@gentoo.org)
6 6
7# char* macchanger_provides(void) 7# char* macchanger_provides(void)
14# void macchanger_depend(void) 14# void macchanger_depend(void)
15# 15#
16# Sets up the dependancies for the module 16# Sets up the dependancies for the module
17macchanger_depend() { 17macchanger_depend() {
18 before interface wireless 18 before interface wireless
19 need interface
20} 19}
21 20
22# bool macchanger_check_installed(void) 21# bool macchanger_check_installed(void)
23# 22#
24# Returns 1 if macchanger is installed, otherwise 0 23# Returns 1 if macchanger is installed, otherwise 0
45 44
46# bool macchanger_pre_start(char *iface) 45# bool macchanger_pre_start(char *iface)
47# 46#
48# Configures the MAC address for iface 47# Configures the MAC address for iface
49macchanger_pre_start() { 48macchanger_pre_start() {
50 local iface=${1} mac opts e old_mac new_mac 49 local iface=${1} mac
51 local ifvar=$( interface_variable ${1} ) 50 local ifvar=$( interface_variable ${1} )
52 51
53 eval mac=\"\$\{mac_${ifvar}\}\" 52 eval mac=\"\$\{mac_${ifvar}\}\"
54 [[ -z ${mac} ]] && return 0 53 [[ -z ${mac} ]] && return 0
55 54
56 mac=$( echo ${mac} | tr '[:lower:]' '[:upper:]' ) 55 mac=$( echo ${mac} | tr '[:upper:]' '[:lower:]' )
57 case "${mac}" in 56 case "${mac}" in
58 # specific mac-addr, i wish there were a shorter way to specify this 57 # 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}" ;; 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}" ;;
60 59
61 # increment MAC address, default macchanger behavior 60 # increment MAC address, default macchanger behavior
62 increment) opts="${opts}" ;; 61 increment) opts="${opts}" ;;
63 62
64 # randomize just the ending bytes 63 # randomize just the ending bytes
75 74
76 # default case is just to pass on all the options 75 # default case is just to pass on all the options
77 *) opts="${opts} ${mac}" ;; 76 *) opts="${opts} ${mac}" ;;
78 esac 77 esac
79 78
80 # The interface needs to be up for macchanger to work 79 # The interface needs to be up for macchanger to work most of the time
81 interface_up ${iface} 80 interface_down ${iface}
82 81
83 ebegin "Changing MAC address of ${iface}" 82 ebegin "Changing MAC address of ${iface}"
84 mac=$( /sbin/macchanger ${opts} ${iface} | awk '/Faked MAC:/ { print $3 }' ) 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
85 if [[ -z ${mac} ]]; then 91 if [[ -z ${mac} ]]; then
86 eend 1 "Failed to set MAC address" 92 eend 1 "Failed to set MAC address"
87 return 1 93 return 1
88 fi 94 fi
89 95

Legend:
Removed from v.756  
changed lines
  Added in v.757

  ViewVC Help
Powered by ViewVC 1.1.20