Skip to content

Instantly share code, notes, and snippets.

@cyb3rsalih
Last active February 27, 2023 13:16
Show Gist options
  • Save cyb3rsalih/c6f04ff5149b42d8d0ae51490539d9f7 to your computer and use it in GitHub Desktop.
Save cyb3rsalih/c6f04ff5149b42d8d0ae51490539d9f7 to your computer and use it in GitHub Desktop.
MAC address Changer for MacOS
#!/bin/bash
# Show the list of network interfaces
echo "Available network interfaces:"
networksetup -listallhardwareports | grep "Hardware Port"
# Prompt the user to enter the interface number
echo "Enter the number of the interface you want to change (e.g., 1 for en0): "
read interface_num
# Construct the interface name based on the number
interface_name="en${interface_num}"
# Get the current MAC address of the interface
current_mac=$(ifconfig "$interface_name" | grep "ether" | awk '{print $2}')
# Generate a random MAC address
generate_mac() {
echo "Generating a random MAC address..."
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
}
random_mac=$(generate_mac)
# Ask the user whether to use the generated MAC address or enter a custom one
echo "The current MAC address of $interface_name is $current_mac."
echo "Do you want to use the generated MAC address $random_mac? (y/n) "
read use_random_mac
# Prompt the user to enter a custom MAC address if desired
if [[ "$use_random_mac" != "y" ]]; then
echo "Enter the new MAC address (in the format xx:xx:xx:xx:xx:xx): "
read new_mac
else
new_mac=$random_mac
fi
# Change the MAC address of the interface
echo "Changing the MAC address of $interface_name to $new_mac..."
sudo ifconfig "$interface_name" ether "$new_mac"
# Verify the new MAC address
echo "Verifying the new MAC address..."
ifconfig "$interface_name" | grep "ether"
# Signature
echo "Script written by ChatGPT (ChatGPT)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment