[#64] Addition of Wireshark abbreviations for OUI manufacturers

This commit is contained in:
Eric A. Miller
2014-01-10 20:13:26 -05:00
parent 7cd99f17dc
commit 19823e13ff
5 changed files with 51 additions and 3 deletions

View File

@@ -5,6 +5,7 @@
* [#32] Show device layers in Details tab
* [#66] Remove reference to "native" VLAN in code and replace with "untagged"
* [#66] DB Schema update to add "native" column to PK of device_port_vlan table
* [#64] Addition of Wireshark abbreviations for OUI manufacturers
[BUG FIXES]

View File

@@ -46,6 +46,7 @@ use Archive::Extract;
$Archive::Extract::PREFER_BIN = 1;
use HTTP::Tiny;
use Try::Tiny;
use Encode;
=head1 NAME
@@ -168,7 +169,9 @@ sub deploy_oui {
if ($line =~ m/^\s*(.{2}-.{2}-.{2})\s+\(hex\)\s+(.*)\s*$/i) {
my ($oui, $company) = ($1, $2);
$oui =~ s/-/:/g;
$data{lc($oui)} = $company;
my $abbrev = shorten($company);
$data{lc($oui)}{'company'} = $company;
$data{lc($oui)}{'abbrev'} = $abbrev;
}
}
@@ -176,7 +179,12 @@ sub deploy_oui {
$schema->txn_do(sub{
$schema->resultset('Oui')->delete;
$schema->resultset('Oui')->populate([
map {{oui => $_, company => $data{$_}}} keys %data
map {
{ oui => $_,
company => $data{$_}{'company'},
abbrev => $data{$_}{'abbrev'}
}
} keys %data
]);
});
}
@@ -185,6 +193,37 @@ sub deploy_oui {
say 'OUI update complete.';
}
# This subroutine is from Wireshark's make-manuf
# http://anonsvn.wireshark.org/wireshark/trunk/tools/make-manuf
sub shorten {
my $manuf = shift;
$manuf = decode "utf8", $manuf, Encode::FB_CROAK;
$manuf = " " . $manuf . " ";
# Remove any punctuation
$manuf =~ tr/',.()/ /;
# & isn't needed when Standalone
$manuf =~ s/ \& / /g;
# Remove any "the", "inc", "plc" ...
$manuf
=~ s/\s(the|inc|incorporated|plc||systems|corp|corporation|s\/a|a\/s|ab|ag|kg|gmbh|co|company|limited|ltd|holding|spa)(?= )//gi;
# Convert to consistent case
$manuf =~ s/(\w+)/\u\L$1/g;
# Remove all spaces
$manuf =~ s/\s+//g;
# Truncate all names to a reasonable length, say, 8 characters.
# If the string contains UTF-8, this may be substantially more than 8 bytes.
$manuf = substr( $manuf, 0, 8 );
return encode( "utf8", $manuf );
}
sub deploy_mibs {
my $mibhome = dir(shift);

View File

@@ -10,7 +10,7 @@ __PACKAGE__->load_namespaces(
default_resultset_class => 'ResultSet',
);
our $VERSION = 32; # schema version used for upgrades, keep as integer
our $VERSION = 33; # schema version used for upgrades, keep as integer
use Path::Class;
use File::Basename;

View File

@@ -14,6 +14,8 @@ __PACKAGE__->add_columns(
{ data_type => "varchar", is_nullable => 0, size => 8 },
"company",
{ data_type => "text", is_nullable => 1 },
"abbrev",
{ data_type => "text", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("oui");

View File

@@ -0,0 +1,6 @@
BEGIN;
ALTER TABLE oui ADD COLUMN abbrev text;
COMMIT;