MAC changer

Hello

Can anyone please provide me with script to randomise MAC on each reboot on my Opal router?

I am total beginner in scripting, so I cannot do it by myself.

Why?I brazenly use the neighbouring cafe’s wifi (no password). :sweat_smile:

But they ban my MAC addresses sometimes. I want to make it so that when I reboot, the new MAC is automatically set.

I need a script that will generate a new MAC address on all interfaces on reboot.

I found this solution:


#!/bin/sh /etc/rc.common

START=99

start() {
    # Generate a random MAC address
    new_mac=$(macchanger -r eth0 | awk '/New MAC/ {print $3}')
    
    # Set the new MAC address for the WAN interface
    ifconfig eth0 down
    ifconfig eth0 hw ether $new_mac
    ifconfig eth0 up
    
    # Log the changed MAC address
    logger -t ChangeWANMAC "WAN MAC address changed to: $new_mac"
}

boot() {
    start
}

reload() {
    start
}

But it is not the case. I needt o change MAC on BSSID (like for devices connect to router). I need exactly on ALL interfaces…

And it will be better if it will be done without external package.

generate_random_mac() {
    local parts=()
    for _ in {1..6}; do
        parts+=("$(printf '%02X' $((RANDOM % 256)))")
    done
    
    echo "${parts[*]//\ /:}"
}

Thing above generated by Claude AI - maybe it will work?

@moderators can anybody help?

Found another variant:


#!/bin/sh /etc/rc.common

START=99

start() {
    # Get a list of all network interfaces
    interfaces=$(ip link | awk -F: '$0 !~ "lo|vir|wl|^[^0-9]"{print $2;getline}')
    
    # Loop through each interface
    for interface in $interfaces; do
        # Generate a random MAC address
        new_mac=$(macchanger -r $interface | awk '/New MAC/ {print $3}')
        
        # Set the new MAC address for the current interface
        ifconfig $interface down
        ifconfig $interface hw ether $new_mac
        ifconfig $interface up
        
        # Log the changed MAC address
        logger -t ChangeMAC "MAC address changed to: $new_mac on interface: $interface"
    done
}

boot() {
    start
}

reload() {
    start
}

Will this work?

Try it and report later :wink:

I doubt it, tbh.

Not working :frowning:
Can anyone help me with creating working one?

what router do you have?