<?xml version="1.0" encoding="windows-1252"?>
<node id="97093" title="Find Ethernet Card Manufacturer" created="2001-07-16 17:12:28" updated="2005-08-09 03:39:35">
<type id="1042">
CUFP</type>
<author id="42150">
mvaline</author>
<data>
<field name="doctext">
&lt;p&gt;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.

&lt;p&gt;If you call it like &lt;code&gt;ouilookup.pl &lt;OUI&gt;&lt;/code&gt;, it searches a local copy of the list of registered OUIs available from the IEEE at &lt;a href="http://standards.ieee.org/regauth/oui/oui.txt"&gt;http://standards.ieee.org/regauth/oui/oui.txt&lt;/a&gt;. If the &lt;code&gt;-i&lt;/code&gt; option is used, it actually searches the file on the IEEE website.

&lt;p&gt;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 &lt;i&gt;actual&lt;/i&gt; manufacturer.

&lt;code&gt;
#/usr/bin/perl -w
#
# ouilookup.pl - print out the manufacturer to whom a MAC ID is registered.
#   by Micah Valine &lt;mvaline@buffnet.net&gt;
#
# Under normal operation, the program searches oui.txt, the location of
# which is specified in the variable $oui_location, below. oui.txt may
# by downloaded from &lt;http://standards.ieee.org/regauth/oui/oui.txt&gt;. 
#
# 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 sure
# 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 &lt;&lt; "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 &lt;&lt; "ENDMALFORMED";

I'm sorry, but $ARGV[0] doesn't look like a MAC ID to me. You may enter
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 &lt;&lt; "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 &lt;&lt; "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 (&lt;OUI&gt;) {
		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-&gt;new(Proto=&gt;"tcp", PeerAddr=&gt;$server,
										 PeerPort=&gt;"$port", Reuse=&gt;1);
	$server_sock-&gt;autoflush(1); # set buffering off
	print $server_sock "GET $location HTTP/1.1\nHost: $server:$port\n\n";

	while (&lt;$server_sock&gt;) {
		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;
&lt;/code&gt;</field>
</data>
</node>
