5 # Make-manuf - Creates a file containing ethernet OUIs and their
6 # company IDs. It merges the databases at IEEE and
7 # http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
8 # with entries in our template file.
10 # The script reads the comments at the top of "manuf.tmpl" and writes
11 # them to "manuf". It then joins the manufacturer listing in "manuf.tmpl"
12 # with the listing in "oui.txt", "iab.txt", etc, with the entries in
13 # "manuf.tmpl" taking precedence.
15 # LWP is part of the standard Perl module libwww
17 # As of April 2012 the IEEE content is mostly UTF-8 encoded although some
18 # of the entries feature sequences listed at
19 # http://www.i18nqa.com/debug/utf8-debug.html
22 use open ':encoding(utf8)';
24 eval "require LWP::UserAgent;";
26 die "LWP isn't installed. It is part of the standard Perl\n" .
27 " module libwww. Bailing.\n";
30 $revision = '$Revision$';
31 if ($revision !~ /[0-9]/ ) { $revision = "unknown"; }
33 $agent = LWP::UserAgent->new;
35 $agent->agent("Wireshark make-manuf/$revision");
37 $template = "manuf.tmpl";
38 $wkatmpl = "wka.tmpl";
41 # According to http://standards.ieee.org/regauthmaint.html
42 # the IEEE is adding OUI-28 in January 2014.
43 $oui_url = "http://standards.ieee.org/develop/regauth/oui/oui.txt";
44 $iab_url = "http://standards.ieee.org/develop/regauth/iab/iab.txt";
45 $oui36_url = "http://standards.ieee.org/develop/regauth/oui36/oui36.txt";
46 $cb_url = "http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt";
48 $hp = "[0-9a-fA-F]{2}";
49 $oui_re = "$hp:$hp:$hp";
51 $ieee_re = "$hp-$hp-$hp";
71 my $origmanuf = shift;
72 my $manuf = " " . $origmanuf . " ";
73 # Remove any punctuation
74 $manuf =~ tr/',.()/ /;
75 # & isn't needed when Standalone
77 # Remove any "the", "inc", "plc" ...
78 $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;
79 # Convert to consistent case
80 $manuf =~ s/(\w+)/\u\L$1/g;
83 # Truncate all names to a reasonable length, say, 8 characters.
84 # If the string contains UTF-8, this may be substantially more than 8 bytes.
85 $manuf = substr($manuf, 0, 8);
87 if ($manuf =~ /\Q$origmanuf\E/i) {
90 return sprintf("%-22s # %s", $manuf, $origmanuf);
97 print "Fetching $url.\n";
98 $request = HTTP::Request->new(GET => $url);
99 $result = $agent->request($request);
101 if (!$result->is_success) {
102 die ("Error fetching $url: " . $result->status_line . "\n");
104 return decode("utf-8", $result->content);
107 # Write out the header and populate the OUI list with our entries.
109 open (TMPL, "< $template") ||
110 die "Couldn't open template file for reading ($template)\n";
112 while ($line = <TMPL>) {
114 if ($line !~ /^$oui_re\s+\S/ && $inheader) {
115 $header .= "$line\n";
116 } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
118 # Ensure OUI is all upper-case
120 # $oui_list{$oui} = &shorten($manuf);
121 $oui_list{$oui} = $manuf;
126 # Add IEEE entries for IABs
128 $ieee_list = fetch($iab_url);
130 foreach $line (split(/\n/, $ieee_list)) {
131 # determine the OUI used for IAB (currently only 00-50-C2)
132 if (($iab_tmp, $manuf) = ($line =~ /^\s*($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
133 $iab_base = $iab_tmp;
135 # determine next two bytes
136 if (($iab4, $iab5, $manuf) = ($line =~ /^\s*($hp)($hp)$hp-$hp$hp$hp\s+\(base\s16\)\s+(\S.*)$/)) {
137 $iab = "$iab_base:$iab4:$iab5:00/36";
138 $iab =~ tr /-/:/; # The IEEE bytes are separated by dashes.
139 # Ensure IAB is all upper-case
141 if (exists $oui_list{$iab}) {
142 printf "$iab - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$iab}\"\n";
145 $oui_list{$iab} = &shorten($manuf);
152 if ($iab_total < $min_entries) { die "Too few IAB entries ($iab_total)\n"; }
154 # Add IEEE entries for OUI-36
156 $ieee_list = fetch($oui36_url);
158 foreach $line (split(/\n/, $ieee_list)) {
159 # determine the OUI used for OUI-36 (currently only 00-1B-C5)
160 if (($oui36_tmp, $manuf) = ($line =~ /^\s*($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
161 $oui36_base = $oui36_tmp;
163 # determine next two bytes
164 if (($oui36_4, $oui36_5, $manuf) = ($line =~ /^\s*($hp)($hp)$hp-$hp$hp$hp\s+\(base\s16\)\s+(\S.*)$/)) {
165 $oui36 = "$oui36_base:$oui36_4:$oui36_5:00/36";
166 $oui36 =~ tr /-/:/; # The IEEE bytes are separated by dashes.
167 # Ensure OUI-36 is all upper-case
168 $oui36 =~ tr/a-f/A-F/;
169 if (exists $oui_list{$oui36}) {
170 printf "$oui36 - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui36}\"\n";
173 $oui_list{$oui36} = &shorten($manuf);
180 if ($oui36_total < $min_entries) { die "Too few OUI-36 entries ($oui36_total)\n"; }
182 # Add IEEE entries for OUIs not yet known.
184 $ieee_list = fetch($oui_url);
186 foreach $line (split(/\n/, $ieee_list)) {
187 if (($oui, $manuf) = ($line =~ /^\s*($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
188 $oui =~ tr /-/:/; # The IEEE bytes are separated by dashes.
189 # Ensure OUI is all upper-case
191 if (exists $oui_list{$oui}) {
192 printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
195 $oui_list{$oui} = &shorten($manuf);
202 if ($oui_total < $min_entries) { die "Too few OUI entries ($oui_total)\n"; }
204 # Add CaveBear entries for OUIs not yet known.
206 $cb_list = fetch($cb_url);
208 foreach $line (split(/\n/, $cb_list)) {
209 if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
210 ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/); # The CaveBear bytes have no separators
211 $oui = "$h1:$h2:$h3";
212 # Ensure OUI is all upper-case
214 if (exists $oui_list{$oui}) {
215 # printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
218 printf "$oui - adding \"$manuf\" from CaveBear\n";
219 $oui_list{$oui} = &shorten($manuf);
226 if ($cb_total < $min_entries) { die "Too few CaveBear entries ($cb_total)\n"; }
230 open (OUT, "> $outfile") ||
231 die "Couldn't open output file for writing ($outfile)\n";
233 print(OUT "# This file was generated by running ./make-manuf.\n");
234 print(OUT "# Don't change it directly, change manuf.tmpl and wka.tmpl instead.\n#\n");
235 print(OUT "$header");
237 foreach $oui (sort(keys %oui_list)) {
238 print(OUT "$oui\t$oui_list{$oui}\n");
241 # Write out a blank line separating the OUIs from the well-known
242 # addresses, and then read the well-known address template file
243 # and write it to the manuf file.
245 open (WKATMPL, "< $wkatmpl") ||
246 die "Couldn't open well-known address template file for reading ($wkatmpl)\n";
248 # XXX - it'd be nice to get this from the Cavebear file, but inferring
249 # the address mask from entries in that file involves some work.
252 while ($line = <WKATMPL>) {
254 print(OUT "$line\n");
257 $total_added = $tmpl_added + $cb_added + $oui_added + $iab_added;
259 Original entries : $tmpl_added
260 IEEE OUI added : $oui_added
261 IEEE IAB added : $iab_added
262 IEEE OUI36 added : $oui36_added
263 CaveBear added : $cb_added
266 IEEE OUI skipped : $oui_skipped
267 IEEE IAB skipped : $iab_skipped
268 IEEE OUI36 skipd : $oui36_skipped
269 CaveBear skipped : $cb_skipped