Net::MAC::Vendor(3pm) | User Contributed Perl Documentation | Net::MAC::Vendor(3pm) |
Net::MAC::Vendor - Look up the vendor for a MAC
version 1.268
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
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.
The IEEE moves the location of its OUI file. If they do that again, you can set the "NET_MAC_VENDOR_OUI_URL" environment variable to get the new URL without updating the code.
Here are some of the old URLs, which also flip-flop schemes:
http://standards.ieee.org/regauth/oui/oui.txt https://standards.ieee.org/regauth/oui/oui.txt http://standards-oui.ieee.org/oui.txt http://standards-oui.ieee.org/oui/oui.txt
There are older copies of the OUI file in the GitHub repository.
These files are large (about 4MB), so you might want to cache a copy.
A different source of information is linuxnet.ca that publishes sanitized and compressed versions of the list, such as:
http://linuxnet.ca/ieee/oui.txt.bz2
The module can read and decompress compressed versions (as long as the url reflects the compression type in the filename as the linuxnet.ca links do).
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.
This makes a direct request to the IEEE website for that OUI to return the information for that vendor.
The "normalize_mac()" function explains the possible formats 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
The input string can also be a blessed NetAddr::MAC object.
The "normalize_mac()" function explains the possible formats for MAC.
To avoid multiple calls on the network, use "load_cache" to preload the entire OUI space into an in-memory cache. This can take a long time over a slow network, though; the file is about 60,000 lines.
Also, the IEEE website has been flaky lately, so loading the cache is better. This distribution comes with several versions of the complete OUI data file.
The "normalize_mac()" function explains the possible formats for MAC.
The "normalize_mac()" function explains the possible formats for MAC.
The "normalize_mac()" function explains the possible formats for MAC.
To avoid multiple calls on the network, use "load_cache" to preload the entire OUI space into an in-memory cache.
If it doesn't find the MAC in the cache, it returns nothing.
Returns false if it could not extract the information. This could mean unexpected input or a change in format.
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.
With no arguments, it returns an empty anonymous array.
By default, this uses the URL from "oui_url", but given an argument, it tries to use that.
If the url indicates that the data is compressed, the response content is decompressed before being stored.
If "load_cache" cannot load the data, it issues a warning and returns nothing.
This previously used DBM::Deep if it was installed, but that was much too slow. Instead, if you want persistence, you can play with $Net::MAC::Vendor::Cached yourself.
If you want to store the data fetched for later use, add a destination filename to the request. To fetch from the default location and store, specify "undef" as source.
Eventually I want people to write their own caching classes so I've created some class methods for this.
1; __END__
Net::MacMap
Bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Net-MAC-Vendor> (or bug-Net-MAC-Vendor@rt.cpan.org <mailto:bug-Net-MAC-Vendor@rt.cpan.org>).
I am also usually active on irc, as 'ether' at "irc.perl.org" and "irc.libera.chat".
brian d foy <bdfoy@cpan.org>
This software is Copyright (c) 2004 by brian d foy.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
2022-02-12 | perl v5.34.0 |