Hello. This has been driving me crazy. I am new to Apple Script and I cannot figure out how to do this, and I can’t seem to find the right solution.
Here is what I need to do, get the MAC address of the active wired ethernet connection. I have tried this:
set macadd to do shell script ("ifconfig en0 | grep ether | cut-c8-2")
That works, but in a strange, rare case that the enabled wired ethernet connection IS NOT en0k, this would be incorrect.
Would something like this work?
set macadd to do shell script ("ifconfig en0 | grep 'netmask 0xffffffff'" -A 1)
Would it be possible to use System Profiler? I’d rather just go that route, because you could select the wired ethernet connection and the script could search to find the ethernet connection that has a subnet mask of 255.255.255.255 (We’re running a speciality quarantine network where all ‘unauthorized’ systems cannot see other computers on the network until they are registered with us.)
Here is what I figured out… With a bit of help from digging through pages of ‘Address’ search results, since the term MAC is shorter than 4 characters, and trial and error.
set ipData to do shell script ("ifconfig |grep 'netmask 0xffffffff' -A 1") as string
set macLoc to (offset of "ether" in ipData) + 6
set MacAdd to ""
repeat with x from macLoc to (macLoc + 16)
set MacAdd to MacAdd & character x of ipData
end repeat
MacAdd
This will find out which ones are up, and their MAC addresses.
set enStatus to {missing value, missing value, missing value, missing value}
set macAdd to {}
repeat with k from 0 to 3
try
if word 1 of (do shell script "ifconfig en" & k & " | grep -B 1 UP,") = "en" & k then set item (k + 1) of enStatus to true
set end of macAdd to do shell script "ifconfig en" & k & " | grep ether | cut -c 8-24"
on error e
if e contains "non-zero status" or e contains "does not exist" then set item (k + 1) of enStatus to false
set end of macAdd to "missing value"
end try
end repeat
I’m sure I have done this in the Past?,
Any way your scripts did not work for me, so I tweaked it.
I do not use the Built in ethernet but a extra one in a PCI Slot on my G5.
this picks up the Active ether.
try
set ipData to paragraph 1 of (do shell script ("ifconfig |grep ether -A 1|grep -w active -B 1|grep ether |awk 'BEGIN { FS=" & "\" \" " & " ;} {" & "
" & " printf( $2 ); }'")) as string
on error
set ipData to "Can not Determine MAC address"
end try
return ipData
Ahh, thanks for that, Mark. My unix skills were not up to your version.