http://www.perlmonks.org?node_id=97093

The first three octets of an ethernet MAC address comprise the Organizational Unique Identifier (OUI) granted to ethernet card manufacturers by the IEEE. Occasionally, it is useful to be able to find the manufacturer of a particular card, so I wrote a script to do so.

If you call it like ouilookup.pl <OUI>, it searches a local copy of the list of registered OUIs available from the IEEE at http://standards.ieee.org/regauth/oui/oui.txt. If the -i option is used, it actually searches the file on the IEEE website.

This is not a perfect way to find the manufacturer because according to the IEEE, not all companies assigned an OUI have elected to make their OUI public. In addition, because subcontracting, the holder of the OUI may not be the actual manufacturer.

#/usr/bin/perl -w # # ouilookup.pl - print out the manufacturer to whom a MAC ID is regist +ered. # by Micah Valine <mvaline@buffnet.net> # # Under normal operation, the program searches oui.txt, the location o +f # which is specified in the variable $oui_location, below. oui.txt may # by downloaded from <http://standards.ieee.org/regauth/oui/oui.txt>. # # If the -i option is used, the program will examine the file directly # from the IEEE website. It's significantly slower, but one can be sur +e # you are getting up to date information. # use warnings; use strict; use IO::Socket; # program settings my $oui_location = "x:\\bin\\oui.txt"; # global variables my $oui; my $foundit = 0; my $input_type; my $output; my $optioni = 0; my $server = "standards.ieee.org"; my $port = "80"; my $location = "/regauth/oui/oui.txt"; my $server_sock; # usage: print usage information and die sub usage() { print STDERR << "ENDUSAGE"; usage: maclookup.pl [-i] OUI -i searches the IEEE website rather than a local file ENDUSAGE exit 1; } # malformed: tell the user his input doesn't look right sub malformed { print STDERR << "ENDMALFORMED"; I'm sorry, but $ARGV[0] doesn't look like a MAC ID to me. You may ente +r MAC IDs in two formats: hexadecimal, which looks like (XX-XX-XX), or base 16, which looks like (XXXXXX). ENDMALFORMED exit 1; } # notfound: tell the user that we didn't find his input sub notfound { print STDERR << "ENDNOTFOUND"; Unfortunately, I couldn't find a listing for $ARGV[0]. You may wish to download an updated copy of oui.txt from IEEE at http://standards.ieee.org/regauth/oui/oui.txt. ENDNOTFOUND exit 1; } #notfoundi: tell the user we didn't find his input on the internet sub notfoundi { print STDERR << "ENDNOTFOUNDI"; Unfortunately, I couldn't find a listing for $ARGV[1]. I was looking at the file on the IEEE website, so I'm pretty sure the number is an unregistered one. ENDNOTFOUNDI exit 1; } # program entry point usage() unless ($ARGV[0]); if ($ARGV[0] eq "-i") { $optioni = 1; if ($ARGV[1] =~ /\w{2}-\w{2}-\w{2}/) { $input_type = "hex"; $oui = $ARGV[1]; } elsif ($ARGV[1] =~ /\w{6}/) { $input_type = "base16"; $oui = $ARGV[1]; } else { malformed(); } } elsif ($ARGV[0] =~ /\w{2}-\w{2}-\w{2}/) { $input_type = "hex"; $oui = $ARGV[0]; } elsif ($ARGV[0] =~ /\w{6}/) { $input_type = "base16"; $oui = $ARGV[0]; } else { malformed(); } # perform the search if (!$optioni) { open(OUI, $oui_location) or die "Sorry, I can't find $oui_location +: $!\n"; while (<OUI>) { chomp; if (/$oui/) { $output = $_; $foundit = 1; last; } } close(OUI); if (!$foundit) { notfound(); } else { $output =~ s/\w{2}-\w{2}-\w{2}|^\w{6}//g; $output =~ s/\(hex\)|\(base 16\)//g; $output =~ s/^\s+//g; print "$output\n"; } } else { $server_sock = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>$serv +er, PeerPort=>"$port", Reuse=>1); $server_sock->autoflush(1); # set buffering off print $server_sock "GET $location HTTP/1.1\nHost: $server:$port\n\ +n"; while (<$server_sock>) { chomp; if (/$oui/) { $output = $_; $foundit = 1; last; } } close($server_sock); if (!$foundit) { notfoundi(); } else { $output =~ s/\w{2}-\w{2}-\w{2}|^\w{6}//g; $output =~ s/\(hex\)|\(base 16\)//g; $output =~ s/^\s+//g; print "$output\n"; } } exit;