Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Find Ethernet Card Manufacturer

by mvaline (Friar)
on Jul 18, 2001 at 22:39 UTC ( [id://97818]=note: print w/replies, xml ) Need Help??


in reply to Find Ethernet Card Manufacturer

I have heeded the advice of my wise elders and attempted to turn this script into a module.
package OUILookup; require Exporter; use LWP::Simple; use strict; use warnings; our @ISA = qw(Exporter); our @EXPORT = qw(get_oui_owner set_oui_location); our $VERSION = 1.00; my $oui_address = "http://standards.ieee.org/regauth/oui/oui.txt"; my $oui_location = "oui.txt"; sub get_oui_owner { my ($mac) = @_; my $oui = validate_input($mac); my $oui_entry; my $foundit = 0; if ($oui eq "invalid address format") { return $oui; } else { if (update_ouidb()) { open(OUI, $oui_location) or die "Unable to locate $oui_loc +ation: $!\n"; while (<OUI>) { chomp; if (/$oui/) { $oui_entry = $_; $foundit = 1; last; } } close(OUI); if (!$foundit) { return "OUI not found"; } else { $oui_entry =~ s/\w{2}-\w{2}-\w{2}|^\w{6}//g; $oui_entry =~ s/\(hex\)|\(base 16\)//g; $oui_entry =~ s/^\s+//g; return $oui_entry; } } } } sub update_ouidb { my $errcode = mirror("http://standards.ieee.org/regauth/oui/oui.tx +t", $oui_location); if (!($errcode eq "200" || "304")) { die "problem updating OUI database: $!\n"; } else { return 1; } } sub validate_input { my ($input) = @_; my @bytes; my $oui; if ($input =~ /\w{2}-\w{2}-\w{2}-\w{2}-\w{2}-\w{2}/) { @bytes = split '-', $input; $oui = join '-', $bytes[0], $bytes[1], $bytes[2]; return $oui; } else { return "invalid address format"; } } sub set_oui_location { my ($new_value) = @_; $oui_location = $new_value; } 1; =head1 NAME OUILookup =head1 SYNOPSIS Find the owner of the IEEE Organizationally Unique Identifier (OUI) for a particular MAC address. OUILookup uses the IEEE database from <http://standards.ieee.org/regau +th/oui/oui.txt>. It will create a local copy of that database if one does not already e +xist, and update a the local copy if it does exist. By default, the local copy will be stored as oui.txt in the same direc +tory as the script. This location may be set by set_oui_location($new_location). =head1 USAGE use OUILookup; $mac = "00-10-5A-1B-C3-30"; $owner = get_oui_owner($mac); =head1 REQUIRES LWP::Simple =head1 TESTED Perl 5.6.0 on Windows NT (Service Pack 6) =head1 AUTHOR Micah Valine <mvaline@buffnet.net> =cut

Updated: Thanks to Allowing user to change module variables, I have added set_oui_location to allow the user to specify where the oui.txt file is mirrored.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://97818]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found