Wednesday, April 8, 2009

Use MAC Address to Look Up Computer In Open Directory

Occassionally you know a Mac computer is in your Open Directory, but don't know what it is named in there. If you know the primary MAC address, you can look it up.

After you open up a trusty Terminal, you can make a list of all of the Computer Names and their Mac addresses by doing this (on one line):

dscl /LDAPv3/ -readall /Computers RecordName macAddress > out.txt

Then, open up out.txt in a text editor, and do a search for your MAC address, or, from the command line, do this:

grep -A 1 "00:1b:63:36:95:35" out.txt

The result will look like:

dsAttrTypeNative:macAddress: 00:1b:63:36:95:35

If you have access to a computer over ssh or ARD, you can get the MAC address with this command:

ifconfig en0 | grep eth

'en0' is the first interface, which is almost always ethernet, and should be the value stored in the directory. Using 'en1' would give you the second interface's MAC address; it is almost always the Airport.