Skip to content

Instantly share code, notes, and snippets.

@johannrichard
Last active October 12, 2018 20:08
Show Gist options
  • Save johannrichard/a58e428623d36cdc9e6a19dd1a0bf232 to your computer and use it in GitHub Desktop.
Save johannrichard/a58e428623d36cdc9e6a19dd1a0bf232 to your computer and use it in GitHub Desktop.
InvizBox Go – MAC address change
#!/bin/sh
# Replace this in `/sbin/fixup-mac-address`
. /lib/functions.sh
. /lib/functions/system.sh
. /lib/ramips.sh
partname=""
offset=""
NEW_MAC=
YES=
board=$(ramips_board_name)
case $board in
invizboxgo)
partname=factory
offset=$((0x0004))
;;
*)
echo "Unsupported board"
exit 1
;;
esac
while [ -n "$1" ]; do
case "$1" in
??:??:??:??:??:??) NEW_MAC="$1";;
-y) YES=1;;
*)
cat <<EOF
Unknown option/argument '$1'
Usage: $0 [-y] [<macaddr>]
EOF
exit 1
;;
esac
shift
done
ask_bool() {
local message="$1"
local default="$((! ${2:-0}))"
[ -n "$YES" ] && return 0
echo -n "$message "
read opt
case "$opt" in
y|Y) return 0;;
n|N) return 1;;
*) return $default;;
esac
}
convert_hex() {
hexdump -e '/1 "%02x "'
}
gen_mac() {
dd if=/dev/urandom bs=6 count=1 2>/dev/null
}
mac="$(mtd_get_mac_binary $partname $offset)"
case "$mac" in
00:00:00:00:00:00);;
ff:ff:ff:ff:ff:ff);;
*)
echo "Current MAC address: $mac"
ask_bool "Overwrite (y/N)?" 0 || exit
;;
esac
if [ -n "$NEW_MAC" ]; then
set -- $(echo "$NEW_MAC" | sed 's,:, ,g')
set -- $(printf %02x $(( (0x$1 & 0xfc) | 0x00 ))) $2 $3 $4 $5 $6
else
set -- $(gen_mac | convert_hex)
set -- $(printf %02x $(( (0x$1 & 0xfc) | 0x00 ))) $2 $3 $4 $5 $6
fi
echo "New MAC address: $1:$2:$3:$4:$5:$6"
ask_bool "Write to EEPROM (y/N)?" || exit
part=$(find_mtd_part "$partname")
[ -n "$part" ] || exit
echo -ne "\x$1\x$2\x$3\x$4\x$5\x$6" | dd of=$part conv=notrunc bs=1 count=6 seek=$offset 2>/dev/null
echo "Done"
#!/bin/sh /etc/rc.common
# Run the MAC change script on boot
# Put this into `/etc/init.d/`
# Copyright (C) 2007 OpenWrt.org
START=10
start() {
echo Set new MAC address
# Sets a new MAC address in EEPROM
/sbin/fixup-mac-address -y
}
@johannrichard
Copy link
Author

johannrichard commented Oct 12, 2018

Change InvizBox Go MAC address

The mt7601e chipset on the InvizBox Go does not allow to change the MAC address via ifconfig or luci. However, the MAC address of the WiFi interface is stored in EEPROM and by overwriting the value, you can nevertheless change the MAC address.

Replace the /sbin/fixup-mac-address script with this one to change the MAC address of the WiFi Interface of your InvizBox Go. After you've changed it, you have to reboot the box in order to set it on the interface.

Usage:

/sbin/fixup-mac-address [-y] [<macaddr>]

You can either specify a new MAC address with the [<macaddr>] option or let the script generate a new one automatically. The new MAC address will be written to the EEPROM without further confirmation if you specify the -y option.

If you want to change the MAC address on every boot, simply put the mac-change script into /etc/init.d�/ Don't forget to make the script executable and enable it:

$ chmod +x /etc/init.d/mac-change
$ /etc/init.d/mac-change enable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment