| Net::MAC::Vendor - look up the vendor for a MAC |
Net::MAC::Vendor - look up the vendor for a MAC
use Net::MAC::Vendor;
my $mac = "00:0d:93:29:f6:c2";
my $array = Net::MAC::Vendor::lookup( $mac );
You can also run this as a script with as many arguments as you like. The module realizes it is a script, looks up the information for each MAC, and outputs it.
perl Net/Mac/Vendor.pm 00:0d:93:29:f6:c2 00:0d:93:29:f6:c5
=head1 DESCRIPTION
The Institute of Electrical and Electronics Engineers (IEEE) assigns an Organizational Unique Identifier (OUI) to manufacturers of network interfaces. Each interface has a Media Access Control (MAC) address of six bytes. The first three bytes are the OUI.
This module allows you to take a MAC address and turn it into the OUI and vendor information. You can, for instance, scan a network, collect MAC addresses, and turn those addresses into vendors. With vendor information, you can often guess at what what you are looking at (e.g. an Apple product).
You can use this as a module as its individual functions, or call it as a script with a list of MAC addresses as arguments. The module can figure it out.
This module tries to persitently cache with DBM::Deep the
OUI information so it can avoid using the network. If it
cannot load DBM::Deep, it uses a normal hash (which is lost
when the process finishes). You can preload this cache with
the load_cache() function. So far, the module looks in the
current working directory for a file named mac_oui.db to find
the cache. I need to come up with a way to let the user set
that location.
run() processes each one of them. It prints out what it
discovers.
This method does try to use a cache of OUI to cut down on the times it has to access the network. If the cache is fully loaded (perhaps using load_cache), it may not even use the network at all.
The normalize_mac() function explains the possible formants
for MAC.
The input string can be a separated by colons or hyphens. They can omit leading 0's (which might make things look odd). We only need the first three bytes
00:0d:93:29:f6:c2 # usual form
00-0d-93-29-f6-c2 # with hyphens
00:0d:93 # first three bytes
0:d:93 # missing leading zero
:d:93 # missing all leading zeros
=cut
| sub normalize_mac | |
| { | |
| my $input = uc shift; |
my $mac = join "-",
grep { /^[0-9A-F]{2}$/ }
map { sprintf "%02X", hex }
( split /[:-]/, $input )[0..2];
$mac = undef unless $mac =~ /^[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}$/;
carp "Could not normalize MAC [$input]" unless $mac;
return $mac;
}
The normalize_mac() function explains the possible formants
for MAC.
00-03-93 (hex) Apple Computer, Inc.
000393 (base 16) Apple Computer, Inc.
20650 Valley Green Dr.
Cupertino CA 95014
UNITED STATES
and turns it into an array of lines. It discards the first line, strips the leading information from the second line, and strips the leading whitespace from all of the lines.
fetch_oui() will use this cache if it exists.
This source is part of a SourceForge project which always has the latest sources in CVS, as well as all of the previous releases.
http://sourceforge.net/projects/brian-d-foy/
If, for some reason, I disappear from the world, one of the other members of the project can shepherd this module appropriately.
brian d foy <bdfoy@cpan.org>
Copyright (c) 2004-2005, brian d foy, All Rights Reserved.
You may redistribute this under the same terms as Perl itself.
| Net::MAC::Vendor - look up the vendor for a MAC |