Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

macuser154

macrumors 6502
Original poster
Jan 17, 2009
372
0
UK
I am writing a simple AppleScript that will allow a user to see his/her wireless MAC address. This is what I have so far:

set WirelessMAC to ((do shell script "ifconfig en1 ether"))
display dialog "Would you like to display your MAC address?" buttons {"No", "Yes"} default button 2
if the button returned of the result is "Yes" then display dialog WirelessMAC buttons {"Clipboard", "OK"} default button 2
if the button returned of the result is "Clipboard" then set the clipboard to WirelessMAC

This is the result:

en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 00:11:22:33:44:55

How can I set the script to display the result like this:

00:11:22:33:44:55

Oh, and the Clipboard part of the script is purely to help me paste the result of the script here. It does not need to be part of the final script.

Thankyou all in advance! :)

I would also like to allow the user to change his/her MAC address. I know the command that has to be run in order to do this:

sudo ifconfig en1 ether [New MAC Address]

But I don't know how to allow the user to simply type the new MAC address into a text box and have the above command be run with administrative privileges and with the MAC address the user has specified.
 
Change your ifconfig line to this:
ifconfig en1 |grep ether |cut -d' ' -f2

Standard shell text technique. I did the ifconfig and sent the data (piped) to grep. This returned just: ether 00:14:51:63:83:02. I then sent that (again, piped) to cut delimited by a space (-d' ') and grabbed field 2 (-f2), the address.

I would recommend you do some reading on Bash (the default shell for OS X) and shell techniques.

Edit:
Also, changing MAC addresses at will is NOT recommended. They are supposed to be unique from the factory preventing duplicate issues.
 
Thankyou very much. I know about the dangers of MAC spoofing, I just wanted to write a script that could be used to easily change a users MAC address.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.