Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 <OUI>, it searches a local copy of the list of registered OUIs available from the IEEE at 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 # # - print out the manufacturer to whom a MAC ID is regist +ered. # by Micah Valine <> # # 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 <>. # # 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 = ""; my $port = "80"; my $location = "/regauth/oui/oui.txt"; my $server_sock; # usage: print usage information and die sub usage() { print STDERR << "ENDUSAGE"; usage: [-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 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;

In reply to Find Ethernet Card Manufacturer by mvaline

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (7)
    As of 2019-11-18 09:07 GMT
    Find Nodes?
      Voting Booth?
      Strict and warnings: which comes first?

      Results (88 votes). Check out past polls.