script to change mac adress on eth0 and wlan0

Here you can exchange scripts that you created or have permission to share with other users.
Post Reply
Message
Author
User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

script to change mac adress on eth0 and wlan0

#1 Post by GDixon »

This is a handy way to change the mac adress on the ethernet and wireless cards.
you will need macchanger from the debian repo so install it and take a look at the --help
Macchanger can do a lot but right now I only included -r or random chnging, more will come if others like this.

Network manager will change the mac back to the firmware mac so change it before connecting.


this is for a desktop icon to execute the script, I just place it in /usr/local/bin with all my scripts and then copy it to my desktop. One click to execute.

Remember to make both executable and have fun

Code: Select all

[Desktop Entry]

Version=0.0.1

Name=Cange Mac's

Comment=Changes both network cards Mac's

Exec=/usr/local/bin/changemac

Icon=/usr/share/icons/mconfig.png

Terminal=true

Type=Application

Categories=Applications;Utilities;
This is the main script and i called it changemac

Code: Select all

#!/bin/bash

# You need to install macchanger from the debian repo to use this 
# script to change the mac address of the ethernet and/or wireless cards

# currently as written it will change both at the same time, in the
# near future it will have a menu to choose one or all


# This is to check if your root/superuser and if not prompts you for root's password

if [ $(id -u) != "0" ]; then
/usr/bin/clear
    echo
    echo -e "You must be root/superuser to run this script $USER\n" >&2

# su -c ''  will give a root password prompt for this sesion and then close root when you quit the script

su -c '/usr/local/bin/changemac'

    exit 1
fi

# used to change MAC Address on both cards to random mac's

clear
echo -e "Changing Eth0 cat5 mac address\n"
ifconfig eth0 down
macchanger -r eth0
ifconfig eth0 up
echo
echo -e "\n"
echo -e "Changing wlan0 wireless mac address\n"
ifconfig wlan0 down
macchanger -r wlan0
ifconfig wlan0 up
echo -e "\n"
echo -e "eth0 cat5 and wlan0 wireless mac's are changed\n"
sleep 10
exit 0

User avatar
Jerry3904
Administrator
Posts: 21881
Joined: Wed Jul 19, 2006 6:13 am

Re: script to change mac adress on eth0 and wlan0

#2 Post by Jerry3904 »

I like the way you comment the script sections, it helps me follow what you are doing.
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox and Windows 10
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: script to change mac adress on eth0 and wlan0

#3 Post by GDixon »

The comments keep me from forgetting what i was thinking and makes changes easier.
Heres a small update.
macchanger is capable of more, i'll add to this as time permits and anyone else finds it useful.

fixed a spelling oops

Code: Select all

[Desktop Entry]
Categories=Applications;Utilities;
Comment[en_US]=Changes both network cards Mac's
Comment=Changes both network cards Mac's
Exec=/usr/local/bin/changemac
GenericName[en_US]=
GenericName=
Icon=/usr/share/icons/mconfig.png
MimeType=
Name[en_US]=Change Mac's
Name=Change Mac's
Path=
StartupNotify=true
Terminal=true
TerminalOptions=
Type=Application
Version=0.0.1
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=
Added a menu like in the wol and trim scripts

Code: Select all

#!/bin/bash

# You need to install macchanger from the debian repo to use this 
# script to change the mac address of the ethernet and/or wireless cards


# This is to check if your root/superuser and if not prompts you for root's password

if [ $(id -u) != "0" ]; then
/usr/bin/clear
    echo
    echo -e "You must be root/superuser to run this script $USER\n" >&2

# su -c ''  will give a root password prompt for this sesion and then close root
# when you quit the script or the script is done

su -c '/usr/local/bin/changemac'

    exit 1
fi

# definition of menu

# eth0               added as 1
# wlan0              added as 2
# All                added as a or A
# Quit               added as q or Q

# Variables that can be changed to match system

name=Greg   # insert name of script user you would like to use

# clear the terminal to start fresh

/usr/bin/clear

while [ "$input1" != quit ]; do
    echo
    echo -e "Which network card would you like to change $name?\n"

# These are menu choice descriptions below

    echo -e "1) Change mac on eth0\n"
    echo -e "2) Change mac on wlan0\n"
    echo -e "a) Change mac on both\n"
    echo -e "q) quit and take no further action\n"
    echo -e "Waiting on your choice $name\n"

# to change one at a time

# eth0 cat 5

read input1
if [ $input1 == 1 ]; then
/usr/bin/clear
    echo
    echo -e "Changing Eth0 cat5 mac address $name\n"
  ifconfig eth0 down; macchanger -r eth0; ifconfig eth0 up
echo -e "\n"
echo -e "eth0 cat5 mac is changed\n"
sleep 8; /usr/bin/clear; /usr/local/bin/changemac
exit 1
fi

# wlan0 wireless

if [ $input1 == 2 ]; then
/usr/bin/clear
    echo
    echo -e "Changing wlan0 wireless mac address $name\n"
  ifconfig wlan0 down; macchanger -r wlan0; ifconfig wlan0 up
echo -e "\n"
echo -e "wlan0 wireless mac is changed\n"
sleep 8; /usr/bin/clear; /usr/local/bin/changemac
exit 1
fi

# used to change MAC Address on both cards to random mac's

if [ $input1 == A ] || [ $input1 == a ]; then
/usr/bin/clear

clear
echo -e "Changing Eth0 cat5 mac address\n"

ifconfig eth0 down; macchanger -r eth0; ifconfig eth0 up

echo
echo -e "\n"
echo -e "Changing wlan0 wireless mac address\n"

ifconfig wlan0 down; macchanger -r wlan0; ifconfig wlan0 up

echo -e "\n"
echo -e "eth0 cat5 and wlan0 wireless mac's are changed\n"

# uncomment one line below to go back to script 
# menu after choosing all

#sleep 12; /usr/bin/clear; /usr/local/bin/changemac

# If one lineabove is used to go back to script
# menu then comment out 4 lines below
 
# these 4 lines below will exit script when all
# is chosen

sleep 12; clear
echo
echo -e "Later gator!\n"
sleep 2; clear

exit 1
fi

if [ $input1 == Q ] || [ $input1 == q ]; then
/usr/bin/clear
    echo
    echo -e "later gator!\n"
sleep 2; /usr/bin/clear 
   
exit 1
fi

    done

I'm working on packing these into deb with debreate. fun fun fun learnming so far.

User avatar
Jerry3904
Administrator
Posts: 21881
Joined: Wed Jul 19, 2006 6:13 am

Re: script to change mac adress on eth0 and wlan0

#4 Post by Jerry3904 »

Here's a basic question: in what situation would I ever want to use this?
Production: 5.10, MX-23 Xfce, AMD FX-4130 Quad-Core, GeForce GT 630/PCIe/SSE2, 16 GB, SSD 120 GB, Data 1TB
Personal: Lenovo X1 Carbon with MX-23 Fluxbox and Windows 10
Other: Raspberry Pi 5 with MX-23 Xfce Raspberry Pi Respin

User avatar
GDixon
Posts: 51
Joined: Fri Nov 02, 2007 4:39 pm

Re: script to change mac adress on eth0 and wlan0

#5 Post by GDixon »

I use it at Dunkin Donuts, cafes, Mcdonalds and free wifi spots to change the mac and get a new ip address. Sometimes you get throttled and a refresh with a new ip works wonders.

Also it's used to change a mac when downloading with a p2p site. It's weak masking but it's deniable plausibility.

Lastly it's been interesting and a learning curve with scripts, I have some of the simple script commands down ok and it's time to make things a bit more complicated finding better ways with more things in scripting.

Post Reply

Return to “Scripts”