Last active
June 18, 2024 09:52
-
-
Save mbierman/03b2a962ac04963ef5bbc8354d0ed5d1 to your computer and use it in GitHub Desktop.
NOTE: Looks like Apple killed tis in Sonoma. There may be no viable workaround. If I find one, I will update this script. This allows you to create and assign any MAC address you like for macOS Wi-Fi or Ethernet connections. If you don’t supply one a random mac will be created for you.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# v 1.0.2 | |
# https://gist.github.com/mbierman/03b2a962ac04963ef5bbc8354d0ed5d1 | |
# 2022 mbierman | |
sleep="${1:-5}" | |
regex="^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$" | |
getmac () { | |
rnd=$(openssl rand -hex 6 | sed 's/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1:\2:\3:\4:\5:\6/') | |
echo -e "What is the mac address want to set the mac\n\nexample: CA:49:63:9F:78:27\n\nLeave blank to get one generated for you." | |
read tmp | |
mac1=${tmp:=$rnd} | |
mac=$(echo $mac1 | tr '[:lower:]' '[:upper:]') | |
if [[ $mac =~ $regex ]] ; then | |
comp=true | |
echo -e "\n\n Using $mac...\n" | |
else | |
comp=false | |
echo false | |
fi | |
} | |
until [ "$comp" = "true" ] | |
do | |
getmac | |
done | |
getAdapter () { | |
echo "What is the adapter you want to set the mac for [en0,en1, etc. use 'ifconfig' if you don't know]" | |
read adapter | |
} | |
until [ "$adapter" ] | |
do | |
getAdapter | |
done | |
type=$(ifconfig $adapter | grep baseT) | |
if [ "$type" ]; then | |
echo "got Ethernet" | |
type="Ethernet" | |
else | |
echo "got Wi-Fi" | |
type="Wi-Fi" | |
fi | |
read -p "Is $adapter $type (y|n) ? " -n 1 -r | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
echo "Exiting. Run again" | |
exit | |
fi | |
sudo ifconfig $adapter down && sleep $sleep && sudo ifconfig $adapter up && \ | |
sudo ifconfig $adapter ether $mac && sudo networksetup -detectnewhardware |
blueDesert
commented
May 13, 2024
via email
•
The Wifi Device's information is as below:
(Attached next reply)
When I used the ifconfig to change the MAC address, it got the error
message.
(Attached next reply)
Michael Bierman ***@***.***> 於 2024年5月13日 週一 上午5:24寫道:
… ***@***.**** commented on this gist.
------------------------------
It's not woking on MACOS sonoma 14.4.1 (23E224), MacBook Air, Apple M1. It
showed the error message: "ifconfig: ioctl (SIOCAIFADDR): Can't assign
requested address"
What is the interface of your Wi-Fi adapter?
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/mbierman/03b2a962ac04963ef5bbc8354d0ed5d1#gistcomment-5054576>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC24BFPNFJ3LVTA6H4MTZ4DZB7MZDBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCOBQGE4TKNRSU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
--
http://services.nexodyne.com/email/icon/vAFpF0qbWpZoK.8u/Jc6XUaI%3D/R01haWw%3D/0/image.png
Looks like Apple killed this in Sonoma. There may be no practical workaround. If I find one, I'll update.
still trying to get it, what's the difference between this simple action that worked couple days ago for me:
- disconnect from wifi network (do not turn off wifi adapter)
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
sudo ifconfig en0 ether xx:xx:xx:xx:xx:xx
- connect back to local wlan
and this script???? o_0
- disconnect from wifi network (do not turn off wifi adapter)
This is very useful for me!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment