Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.
#!/bin/bash
NEWMAC=`openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'`
ifconfig $1 ether $NEWMAC
ifconfig $1 down
ifconfig $1 up

I pass en0 or en1 as the sole argument to the script and run as sudo. When I do this, the MAC does change, however I cannot restore connectivity until I reboot and the new MAC is lost. Initially the interface displays no IP, but after a few minutes it displays an IP and claims to have DHCP information. However, I believe this is a cached data and not an actual renewal, as I cannot ping, load pages, or otherwise connect to the Internet.

I have appended this snippet with no improvement in results.

ipconfig set $1 BOOTP
ipconfig set $1 DHCP
share|improve this question
add comment

1 Answer

If you're on MacOSX 10.5 or later, at the beginning of your script, call sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z. Another thing you could do to improve this is to call the script itself with sudo instead of calling sudo multiple times within.

share|improve this answer
    
When I have sudo ifconfig $1 down before sudo ifconfig $1 ether $NEWMAC, I get this error: ifconfig: ioctl (SIOCAIFADDR): Device power is off. I've modified the script to require sudo when calling the script. –  trav1th May 27 '12 at 23:13
    
Oh, my bad. I'll edit my answer. Did using sudo ifconfig set $1 DHCP work for you? –  Andrew Larsson May 27 '12 at 23:19
    
Just tested it... results in ifconfig: interface set does not exist and the connection remains down. –  trav1th May 27 '12 at 23:28
    
Oh, I messed up, and I edited my answer again. –  Andrew Larsson May 27 '12 at 23:34
    
Oh, I think it's ipconfig and not ifconfig for this command, sorry. I get the two mixed up. Answer updated. –  Andrew Larsson May 27 '12 at 23:39
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.