Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://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 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;

In reply to Find Ethernet Card Manufacturer by mvaline

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-16 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found