2000-11-23 18:22:00 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
#
|
2002-08-03 23:09:24 +00:00
|
|
|
# $Id: make-manuf,v 1.6 2002/08/03 23:09:24 jmayer Exp $
|
2000-11-23 18:22:00 +00:00
|
|
|
#
|
|
|
|
# Make-manuf - Creates a file containing ethernet OUIs and their
|
|
|
|
# company IDs. It merges the databases at
|
|
|
|
# http://standards.ieee.org/regauth/oui/index.shtml and
|
|
|
|
# http://www.cavebear.com/CaveBear/Ethernet/
|
|
|
|
# with entries in our template file.
|
|
|
|
#
|
|
|
|
# The script reads the comments at the top of "manuf.tmpl" and writes
|
|
|
|
# them to "manuf". It then joins the manufacturer listing in "manuf.tmpl"
|
|
|
|
# with the listing in "oui.txt", with the entries in "manuf.tmpl" taking
|
|
|
|
# precedence.
|
|
|
|
|
2001-10-07 22:19:14 +00:00
|
|
|
# LWP is part of the standard Perl module libwww
|
2000-11-23 18:22:00 +00:00
|
|
|
eval "require LWP::UserAgent;";
|
|
|
|
if( $@ ) {
|
2001-10-07 22:19:14 +00:00
|
|
|
die "LWP isn't installed. It is part of the standard Perl\n" .
|
|
|
|
" module libwww. Bailing.\n";
|
2000-11-23 18:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$template = "manuf.tmpl";
|
|
|
|
$outfile = "manuf";
|
|
|
|
$inheader = 1;
|
2002-08-03 23:09:24 +00:00
|
|
|
$ieee_url = "http://standards.ieee.org/regauth/oui/oui_public.txt";
|
2000-11-23 18:22:00 +00:00
|
|
|
$cb_url = "http://www.cavebear.com/CaveBear/Ethernet/Ethernet.txt";
|
|
|
|
%oui_list = ();
|
|
|
|
$hp = "[0-9a-fA-F]{2}";
|
|
|
|
$oui_re = "$hp:$hp:$hp";
|
|
|
|
$cb_re = "$hp$hp$hp";
|
|
|
|
$ieee_re = "$hp-$hp-$hp";
|
|
|
|
|
|
|
|
$tmpl_added = 0;
|
|
|
|
$cb_added = 0;
|
|
|
|
$cb_skipped = 0;
|
|
|
|
$ieee_added = 0;
|
|
|
|
$ieee_skipped = 0;
|
|
|
|
|
|
|
|
$agent = LWP::UserAgent->new;
|
|
|
|
|
|
|
|
print "Fetching $cb_url.\n";
|
|
|
|
$request = HTTP::Request->new(GET => $cb_url);
|
|
|
|
$result = $agent->request($request);
|
|
|
|
|
|
|
|
if (!$result->is_success) {
|
|
|
|
die ("Error fetching $cb_url: " . $result->status_line . "\n");
|
|
|
|
}
|
|
|
|
$cb_list = $result->content;
|
|
|
|
|
|
|
|
print "Fetching $ieee_url.\n";
|
|
|
|
$request = HTTP::Request->new(GET => $ieee_url);
|
|
|
|
$result = $agent->request($request);
|
|
|
|
|
|
|
|
if (!$result->is_success) {
|
|
|
|
die ("Error fetching $ieee_url: " . $result->status_line . "\n");
|
|
|
|
}
|
|
|
|
$ieee_list = $result->content;
|
|
|
|
|
|
|
|
open (TMPL, "< $template") ||
|
|
|
|
die "Couldn't open template file for reading ($template)\n";
|
|
|
|
|
|
|
|
open (OUT, "> $outfile") ||
|
2002-03-14 21:22:11 +00:00
|
|
|
die "Couldn't open output file for writing ($outfile)\n";
|
2000-11-23 18:22:00 +00:00
|
|
|
|
|
|
|
# Write out the header and populate the OUI list with our entries.
|
|
|
|
while ($line = <TMPL>) {
|
|
|
|
chomp($line);
|
|
|
|
if ($line !~ /^$oui_re\s+\S/ && $inheader) {
|
|
|
|
print(OUT "$line\n");
|
|
|
|
} elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
|
|
|
|
$inheader = 0;
|
2000-11-29 04:11:48 +00:00
|
|
|
# Ensure OUI is all upper-case
|
|
|
|
$oui =~ tr/a-f/A-F/;
|
2000-11-23 18:22:00 +00:00
|
|
|
$oui_list{$oui} = $manuf;
|
|
|
|
$tmpl_added++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-02 11:07:47 +00:00
|
|
|
# Add IEEE entries for OUIs not yet known.
|
|
|
|
foreach $line (split(/\n/, $ieee_list)) {
|
|
|
|
if (($oui, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
|
|
|
|
$oui =~ tr /-/:/; # The IEEE bytes are separated by dashes.
|
2000-11-29 04:11:48 +00:00
|
|
|
# Ensure OUI is all upper-case
|
|
|
|
$oui =~ tr/a-f/A-F/;
|
2000-11-23 18:22:00 +00:00
|
|
|
if (exists $oui_list{$oui}) {
|
2002-05-02 11:07:47 +00:00
|
|
|
printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
|
|
|
|
$ieee_skipped++;
|
2000-11-23 18:22:00 +00:00
|
|
|
} else {
|
|
|
|
$oui_list{$oui} = $manuf;
|
2002-05-02 11:07:47 +00:00
|
|
|
$ieee_added++;
|
2000-11-23 18:22:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-02 11:07:47 +00:00
|
|
|
# Add CaveBear entries for OUIs not yet known.
|
|
|
|
foreach $line (split(/\n/, $cb_list)) {
|
|
|
|
if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
|
|
|
|
($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/); # The CaveBear bytes have no separators
|
|
|
|
$oui = "$h1:$h2:$h3";
|
2000-11-29 04:11:48 +00:00
|
|
|
# Ensure OUI is all upper-case
|
|
|
|
$oui =~ tr/a-f/A-F/;
|
2000-11-23 18:22:00 +00:00
|
|
|
if (exists $oui_list{$oui}) {
|
2002-05-02 11:07:47 +00:00
|
|
|
printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
|
|
|
|
$cb_skipped++;
|
2000-11-23 18:22:00 +00:00
|
|
|
} else {
|
|
|
|
$oui_list{$oui} = $manuf;
|
2002-05-02 11:07:47 +00:00
|
|
|
$cb_added++;
|
2000-11-23 18:22:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach $oui (sort(keys %oui_list)) {
|
|
|
|
print(OUT "$oui\t$oui_list{$oui}\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
$total_added = $tmpl_added + $cb_added + $ieee_added;
|
|
|
|
print <<"Fin"
|
|
|
|
Original entries : $tmpl_added
|
|
|
|
IEEE added : $ieee_added
|
2002-05-02 11:07:47 +00:00
|
|
|
CaveBear added : $cb_added
|
2000-11-23 18:22:00 +00:00
|
|
|
Total : $total_added
|
|
|
|
|
|
|
|
IEEE skipped : $ieee_skipped
|
2002-05-02 11:07:47 +00:00
|
|
|
CaveBear skipped : $cb_skipped
|
2000-11-23 18:22:00 +00:00
|
|
|
Fin
|