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 $oui_url = "http://standards.ieee.org/develop/regauth/oui/oui.txt";
42 $iab_url = "http://standards.ieee.org/develop/regauth/iab/iab.txt";
43 $oui36_url = "http://standards.ieee.org/develop/regauth/oui36/oui36.txt";
44 $cb_url = "http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt";
46 $hp = "[0-9a-fA-F]{2}";
47 $oui_re = "$hp:$hp:$hp";
49 $ieee_re = "$hp-$hp-$hp";
63 my $origmanuf = shift;
64 my $manuf = " " . $origmanuf . " ";
65 # Remove any punctuation
66 $manuf =~ tr/',.()/ /;
67 # & isn't needed when Standalone
69 # Remove any "the", "inc", "plc" ...
70 $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;
71 # Convert to consistent case
72 $manuf =~ s/(\w+)/\u\L$1/g;
75 # Truncate all names to a reasonable length, say, 8 characters.
76 # If the string contains UTF-8, this may be substantially more than 8 bytes.
77 $manuf = substr($manuf, 0, 8);
79 if ($manuf =~ /\Q$origmanuf\E/i) {
82 return sprintf("%-22s # %s", $manuf, $origmanuf);
89 print "Fetching $url.\n";
90 $request = HTTP
::Request
->new(GET
=> $url);
91 $result = $agent->request($request);
93 if (!$result->is_success) {
94 die ("Error fetching $url: " . $result->status_line . "\n");
96 return decode
("utf-8", $result->content);
99 # Write out the header and populate the OUI list with our entries.
101 open (TMPL
, "< $template") ||
102 die "Couldn't open template file for reading ($template)\n";
104 while ($line = <TMPL
>) {
106 if ($line !~ /^$oui_re\s+\S/ && $inheader) {
107 $header .= "$line\n";
108 } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
110 # Ensure OUI is all upper-case
112 # $oui_list{$oui} = &shorten($manuf);
113 $oui_list{$oui} = $manuf;
118 # Add IEEE entries for IABs
120 $ieee_list = fetch
($iab_url);
122 foreach $line (split(/\n/, $ieee_list)) {
123 # determine the OUI used for IAB (currently only 00-50-C2)
124 if (($iab_tmp, $manuf) = ($line =~ /^\s*($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
125 $iab_base = $iab_tmp;
127 # determine next two bytes
128 if (($iab4, $iab5, $manuf) = ($line =~ /^\s*($hp)($hp)$hp-$hp$hp$hp\s+\(base\s16\)\s+(\S.*)$/)) {
129 $iab = "$iab_base:$iab4:$iab5:00/36";
130 $iab =~ tr
/-/:/; # The IEEE bytes are separated by dashes.
131 # Ensure IAB is all upper-case
133 if (exists $oui_list{$iab}) {
134 printf "$iab - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$iab}\"\n";
137 $oui_list{$iab} = &shorten
($manuf);
143 # Add IEEE entries for OUI-36
145 $ieee_list = fetch
($oui36_url);
147 foreach $line (split(/\n/, $ieee_list)) {
148 # determine the OUI used for OUI-36 (currently only 00-1B-C5)
149 if (($oui36_tmp, $manuf) = ($line =~ /^\s*($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
150 $oui36_base = $oui36_tmp;
152 # determine next two bytes
153 if (($oui36_4, $oui36_5, $manuf) = ($line =~ /^\s*($hp)($hp)$hp-$hp$hp$hp\s+\(base\s16\)\s+(\S.*)$/)) {
154 $oui36 = "$oui36_base:$oui36_4:$oui36_5:00/36";
155 $oui36 =~ tr
/-/:/; # The IEEE bytes are separated by dashes.
156 # Ensure OUI-36 is all upper-case
157 $oui36 =~ tr/a-f/A-F/;
158 if (exists $oui_list{$oui36}) {
159 printf "$oui36 - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui36}\"\n";
162 $oui_list{$oui36} = &shorten
($manuf);
168 # Add IEEE entries for OUIs not yet known.
170 $ieee_list = fetch
($oui_url);
172 foreach $line (split(/\n/, $ieee_list)) {
173 if (($oui, $manuf) = ($line =~ /^\s*($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
174 $oui =~ tr
/-/:/; # The IEEE bytes are separated by dashes.
175 # Ensure OUI is all upper-case
177 if (exists $oui_list{$oui}) {
178 printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
181 $oui_list{$oui} = &shorten
($manuf);
187 # Add CaveBear entries for OUIs not yet known.
189 $cb_list = fetch
($cb_url);
191 foreach $line (split(/\n/, $cb_list)) {
192 if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
193 ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/); # The CaveBear bytes have no separators
194 $oui = "$h1:$h2:$h3";
195 # Ensure OUI is all upper-case
197 if (exists $oui_list{$oui}) {
198 # printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
201 printf "$oui - adding \"$manuf\" from CaveBear\n";
202 $oui_list{$oui} = &shorten
($manuf);
210 open (OUT
, "> $outfile") ||
211 die "Couldn't open output file for writing ($outfile)\n";
213 print(OUT
"# This file was generated by running ./make-manuf.\n");
214 print(OUT
"# Don't change it directly, change manuf.tmpl and wka.tmpl instead.\n#\n");
215 print(OUT
"$header");
217 foreach $oui (sort(keys %oui_list)) {
218 print(OUT
"$oui\t$oui_list{$oui}\n");
221 # Write out a blank line separating the OUIs from the well-known
222 # addresses, and then read the well-known address template file
223 # and write it to the manuf file.
225 open (WKATMPL
, "< $wkatmpl") ||
226 die "Couldn't open well-known address template file for reading ($wkatmpl)\n";
228 # XXX - it'd be nice to get this from the Cavebear file, but inferring
229 # the address mask from entries in that file involves some work.
232 while ($line = <WKATMPL
>) {
234 print(OUT
"$line\n");
237 $total_added = $tmpl_added + $cb_added + $oui_added + $iab_added;
239 Original entries : $tmpl_added
240 IEEE OUI added : $oui_added
241 IEEE IAB added : $iab_added
242 IEEE OUI36 added : $oui36_added
243 CaveBear added : $cb_added
246 IEEE OUI skipped : $oui_skipped
247 IEEE IAB skipped : $iab_skipped
248 IEEE OUI36 skipd : $oui36_skipped
249 CaveBear skipped : $cb_skipped