MAC Address Vendor Lookup

There are a couple of webpages, including mine (see
http://isquared.nl/doapp.html?appid=mac2vendor
), where you can lookup the manufacturer of a piece of network equipment based on the OUI part of its MAC-address. That’s neat, but not really if the device that you’re trying to identify is, for instance, the rogue DHCP-server that knocked you off the Internet. And apart from that, I rather do as much as I can from within the shell instead of mousing to some website.

That is why I’ve written a small shell-script that does the work for you. Below you’ll find the latest iteration of this script:

mac2vendor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
        #!/bin/bash

        # mac2vendor - lookup the OUI part of a MAC address in the IEEE registration
        # Hessel Schut, hessel@isquared.nl, 2008-10-12

        ouitxt='/usr/share/oui.txt'

        oui=$(sed -ne '{
                # strip all punctuation
                s/[\.:\-]//g

                # convert to uppercase
                s/[a-f]/\u&/g

                # rewrite to canonical format
                s/^\([0-9A-F]\{2\}\)\([0-9A-F]\{2\}\)\([0-9A-F]\{2\}\).*/\1-\2-\3/p
        } ' <<< $1)

        sed -n "/^${oui}/,/^$/p" ${ouitxt}

This script needs a fresh copy of the IEEE OUI assignments list, you can grab one from this location: http://standards.ieee.org/regauth/oui/oui.txt

I use a cronjob that wgets this file every now and then. After that just fire the script with a MAC address as argument, like so:

hessch@blokje:~$ bin/mac2vendor 00:0F:DE:00:00:00
         00-0F-DE   (hex)        Sony Ericsson Mobile Communications AB
         000FDE     (base 16)    Sony Ericsson Mobile Communications AB
        Nya Vattentornet
        Lund SE 221 88
        SWEDEN

The address may be in any of the following common formats:

  • nn-nn-nn-nn-nn-nn
  • nn:nn:nn:nn:nn:nn
  • nnnn.nnnn.nnnn
  • nnnnnnnnnnnn

And anything in between. ;-) Also, it doesn’t need the full address, only entering the first three bytes will do just fine.

Comments