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