Skip to content

Instantly share code, notes, and snippets.

@lixingcong
Created August 17, 2026 06:04
Show Gist options
  • Select an option

  • Save lixingcong/94cc00d65336b8bea8a69b4eb36ff19e to your computer and use it in GitHub Desktop.

Select an option

Save lixingcong/94cc00d65336b8bea8a69b4eb36ff19e to your computer and use it in GitHub Desktop.
openwrt改变接口的mac地址
#!/bin/sh
# OpenWrt random mac address changer
# https://github.com/krabelize/openwrt-random-mac-changer
interface="wlan0"
current_mac=$(ifconfig ${interface} | grep "HWaddr" | awk '{print$5}')
new_mac=$(dd if=/dev/random bs=1 count=3 2>/dev/null | hexdump -C | head -1 | cut -d' ' -f2- | awk '{ print "34:36:3b:"$1":"$2":"$3 }')
if [ $? -eq 0 ]; then
ifconfig $interface down
ifconfig $interface hw ether $new_mac
ifconfig $interface up
if [ $? -eq 0 ]; then
final_mac=$(ifconfig ${interface} | grep "HWaddr" | awk '{print$5}')
logger "MAC address successfully changed for $interface from $current_mac to $new_mac, final_mac=$final_mac"
exit 0
fi
fi
logger "Failed to generate MAC address"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment