#!/usr/bin/perl # mac2ven (c) 2012 Alexander Kuehn # # You may distribute under the terms of either the GNU General Public # License or the Artistic License, as specified in the Perl README file. # use strict; use English; use DBI; if($#ARGV == -1) { print "Usage: $0 MAC [..]\n"; exit 1; } my $dbh = DBI->connect("dbi:SQLite:/var/db/ethercodes.db","","", { RaiseError => 1, AutoCommit => 0 }); # check if the table already exists my @res=$dbh->selectrow_array( q{select count(*) from sqlite_master where type="table" and name="c2v";}); unless($res[0]) { $dbh->do(q{create table c2v ( a int not null, b int not null, c int not null, v text not null, primary key(a,b,c)); }); my $sth=$dbh->prepare(q{replace into c2v(a,b,c,v) values(?,?,?,?);}); for (grep(/^(\w\w)-(\w\w)-(\w\w)\s+.*\t\t(.+)$/, `GET http://standards.ieee.org/regauth/oui/oui.txt`)) { /^(\w\w)-(\w\w)-(\w\w)\s+.*\t\t(.+)$/; $sth->execute(hex($1),hex($2),hex($3),$4); } $dbh->commit; } for(@ARGV) { if(/(\w{1,2}):(\w{1,2}):(\w{1,2})/) { @res=$dbh->selectrow_array( "select v from c2v where a=".hex($1)." and b=".hex($2)." and c=".hex($3).";"); print $res[0] . "\n"; } } $dbh->disconnect;