Subversion Repositories uuid_mac_utils

Rev

Rev 23 | Rev 41 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3
/*
16 daniel-mar 4
 * MAC (EUI-48 and EUI-64) utils for PHP
15 daniel-mar 5
 * Copyright 2017 - 2023 Daniel Marschall, ViaThinkSoft
25 daniel-mar 6
 * Version 2023-07-11
2 daniel-mar 7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
 
18 daniel-mar 21
// Very good resources for information about OUI, EUI, MAC, ...
22
// - https://mac-address.alldatafeeds.com/faq#how-to-recognise-mac-address-application
23
// - https://standards.ieee.org/wp-content/uploads/import/documents/tutorials/eui.pdf
24
// - https://en.m.wikipedia.org/wiki/Organizationally_unique_identifier
25
 
15 daniel-mar 26
const IEEE_MAC_REGISTRY = __DIR__ . '/../web-data';
2 daniel-mar 27
 
15 daniel-mar 28
/**
20 daniel-mar 29
 * Checks if a MAC, EUI, ELI, AAI, SAI, or IPv6-Link-Local address is valid
19 daniel-mar 30
 * @param string $mac MAC, EUI, or IPv6-Link-Local Address
17 daniel-mar 31
 * @return bool True if it is valid
15 daniel-mar 32
 */
33
function mac_valid(string $mac): bool {
17 daniel-mar 34
        $tmp = ipv6linklocal_to_mac48($mac);
16 daniel-mar 35
        if ($tmp !== false) $mac = $tmp;
36
 
2 daniel-mar 37
        $mac = str_replace(array('-', ':'), '', $mac);
38
        $mac = strtoupper($mac);
39
 
16 daniel-mar 40
        if ((strlen($mac) != 12) && (strlen($mac) != 16)) return false;
2 daniel-mar 41
 
42
        $mac = preg_replace('@[0-9A-F]@', '', $mac);
43
 
16 daniel-mar 44
        return ($mac === '');
2 daniel-mar 45
}
46
 
15 daniel-mar 47
/**
20 daniel-mar 48
 * Returns the amount of bits of a MAC, EUI, ELI, AAI, or SAI
16 daniel-mar 49
 * @param string $mac
17 daniel-mar 50
 * @return false|int
16 daniel-mar 51
 */
17 daniel-mar 52
function eui_bits(string $mac) {
53
        if (!mac_valid($mac)) return false;
54
        $mac = mac_canonize($mac, '');
55
        return (int)(strlen($mac)*4);
56
}
57
 
58
/**
20 daniel-mar 59
 * Canonizes a MAC, EUI, ELI, AAI, SAI, or IPv6-Link-Local address
19 daniel-mar 60
 * @param string $mac MAC, EUI, ELI, or IPv6-Link-Local Address
17 daniel-mar 61
 * @param string $delimiter Desired delimiter for inserting between each octet
19 daniel-mar 62
 * @return string|false The canonized address (Note: IPv6-Link-Local becomes EUI-64)
17 daniel-mar 63
 */
16 daniel-mar 64
function mac_canonize(string $mac, string $delimiter="-") {
65
        if (!mac_valid($mac)) return false;
66
 
17 daniel-mar 67
        $tmp = ipv6linklocal_to_mac48($mac);
16 daniel-mar 68
        if ($tmp !== false) $mac = $tmp;
69
 
70
        $mac = strtoupper($mac);
71
        $mac = preg_replace('@[^0-9A-F]@', '', $mac);
72
        if ((strlen($mac) != 12) && (strlen($mac) != 16)) return false;
73
        $mac = preg_replace('@^(..)(..)(..)(..)(..)(..)(..)(..)$@', '\\1'.$delimiter.'\\2'.$delimiter.'\\3'.$delimiter.'\\4'.$delimiter.'\\5'.$delimiter.'\\6'.$delimiter.'\\7'.$delimiter.'\\8', $mac);
74
        return preg_replace('@^(..)(..)(..)(..)(..)(..)$@', '\\1'.$delimiter.'\\2'.$delimiter.'\\3'.$delimiter.'\\4'.$delimiter.'\\5'.$delimiter.'\\6', $mac);
75
}
76
 
77
/**
15 daniel-mar 78
 * @param string $file
25 daniel-mar 79
 * @param string $registry_name
15 daniel-mar 80
 * @param string $mac
81
 * @return false|string
82
 */
25 daniel-mar 83
function _lookup_ieee_registry(string $file, string $registry_name, string $mac) {
16 daniel-mar 84
        $mac = mac_canonize($mac, '');
85
        if ($mac === false) return false;
2 daniel-mar 86
        $begin = substr($mac, 0, 2).'-'.substr($mac, 2, 2).'-'.substr($mac, 4, 2);
87
        $f = file_get_contents($file);
88
 
89
        $f = str_replace("\r", '', $f);
90
 
91
        # We are using a positive-lookahead because entries like the MA-M references have a blank line between organization and address
92
        preg_match_all('@^\s*'.preg_quote($begin, '@').'\s+\(hex\)\s+(\S+)\s+(.*)\n\n\s*(?=[0-9A-F])@ismU', "$f\n\nA", $m, PREG_SET_ORDER);
93
        foreach ($m as $n) {
94
                preg_match('@(\S+)\s+\(base 16\)(.*)$@ism', $n[2], $m);
95
 
15 daniel-mar 96
                if (preg_match('@(.+)-(.+)@ism', $m[1], $o)) {
2 daniel-mar 97
                        $z = hexdec(substr($mac, 6, 6));
98
                        $beg = hexdec($o[1]);
99
                        $end = hexdec($o[2]);
100
                        if (($z < $beg) || ($z > $end)) continue;
101
                } else {
102
                        $beg = 0x000000;
103
                        $end = 0xFFFFFF;
104
                }
105
 
15 daniel-mar 106
                $x = trim(preg_replace('@^\s+@im', '', $m[2]));
2 daniel-mar 107
 
108
                # "PRIVATE" entries are only marked at the "(hex)" line, but not at the "(base16)" line
109
                if ($x == '') $x = trim($n[1]);
110
 
111
                $x = explode("\n", $x);
112
 
25 daniel-mar 113
                // The 12 is hardcoded and is valid for MAC-48 and MAC-64!
114
                // Reason: The length of the prefix is calculated from MAC-48. MAC-64 just extends the vendor-specific part
115
                // end-beg (= range)  OUI24 0xFFFFFF  len=6    12-6 = 6 nibbles prefix
116
                //                    OUI28 0xFFFFF   len=5    12-5 = 7 nibbles prefix
117
                //                    OUI36 0xFFF     len=3    12-3 = 9 nibbles prefix
118
                $prefix_len = 12-strlen(dechex($end-$beg));
2 daniel-mar 119
 
25 daniel-mar 120
                $out = sprintf("%-32s 0x%s\n", "IEEE $registry_name:", substr($mac, 0, $prefix_len));
121
                $out .= sprintf("%-32s 0x%s\n", "Vendor-specific part:", substr($mac, $prefix_len));
15 daniel-mar 122
                $out .= sprintf("%-32s %s\n", "Registrant:", $x[0]);
25 daniel-mar 123
 
2 daniel-mar 124
                foreach ($x as $n => $y) {
125
                        if ($n == 0) continue;
15 daniel-mar 126
                        else if ($n == 1) $out .= sprintf("%-32s %s\n", "Address of registrant:", $y);
127
                        else if ($n >= 2) $out .= sprintf("%-32s %s\n", "", $y);
2 daniel-mar 128
                }
129
 
130
                return $out;
131
        }
132
 
133
        return false;
134
}
135
 
15 daniel-mar 136
/**
17 daniel-mar 137
 * Try to Decapsulate EUI-64 into MAC-48 or EUI-48
16 daniel-mar 138
 * @param string $eui64
17 daniel-mar 139
 * @return false|string If EUI-64 can be converted into EUI-48, returns EUI-48, otherwise returns EUI-64. On invalid input, return false.
16 daniel-mar 140
 */
141
function eui64_to_eui48(string $eui64) {
142
        if (!mac_valid($eui64)) return false;
143
        $eui64 = mac_canonize($eui64, '');
144
        if (eui_bits($eui64) == 48) return mac_canonize($eui64);
20 daniel-mar 145
        if (($eui64[1] != '0') && ($eui64[1] != '4') && ($eui64[1] != '8') && ($eui64[1] != 'C')) return false; // only allow EUI
16 daniel-mar 146
 
17 daniel-mar 147
        if (substr($eui64, 6, 4) == 'FFFF') {
148
                // EUI-64 to MAC-48
16 daniel-mar 149
                return mac_canonize(substr($eui64, 0, 6).substr($eui64, 10, 6));
17 daniel-mar 150
        } else if (substr($eui64, 6, 4) == 'FFFE') {
151
                if ((hexdec($eui64[1])&2) == 2) {
152
                        // Modified EUI-64 to MAC/EUI-48
153
                        $eui64[1] = dechex(hexdec($eui64[1])&253); // remove bit
154
                        return mac_canonize(substr($eui64, 0, 6).substr($eui64, 10, 6));
155
                } else {
156
                        // EUI-64 to EUI-48
157
                        return mac_canonize(substr($eui64, 0, 6).substr($eui64, 10, 6));
158
                }
16 daniel-mar 159
        } else {
160
                return mac_canonize($eui64);
161
        }
162
}
163
 
164
/**
17 daniel-mar 165
 * MAC-48 to EUI-64 Encapsulation
166
 * @param string $mac48 MAC-48 address
167
 * @return false|string EUI-64 address
16 daniel-mar 168
 */
17 daniel-mar 169
function mac48_to_eui64(string $mac48) {
170
        // Note: MAC-48 is used for network hardware; EUI-48 is used to identify other devices and software.
171
        //       MAC48-to-EUI64 Encapsulation uses 0xFFFF middle part
172
        if (!mac_valid($mac48)) return false;
173
        $mac48 = mac_canonize($mac48, '');
174
        if (eui_bits($mac48) == 64) return mac_canonize($mac48);
20 daniel-mar 175
        if (($mac48[1] != '0') && ($mac48[1] != '4') && ($mac48[1] != '8') && ($mac48[1] != 'C')) return false; // only allow EUI
17 daniel-mar 176
 
177
        $eui64 = substr($mac48, 0, 6).'FFFF'.substr($mac48, 6, 6);
178
        return mac_canonize($eui64);
179
}
180
 
181
/**
182
 * EUI-48 to EUI-64 Encapsulation
183
 * @param string $eui48 EUI-48 address
184
 * @return false|string EUI-64 address
185
 */
16 daniel-mar 186
function eui48_to_eui64(string $eui48) {
17 daniel-mar 187
        // Note: MAC-48 is used for network hardware; EUI-48 is used to identify other devices and software.
188
        //       EUI48-to-EUI64 Encapsulation uses 0xFFFF middle part
16 daniel-mar 189
        if (!mac_valid($eui48)) return false;
190
        $eui48 = mac_canonize($eui48, '');
191
        if (eui_bits($eui48) == 64) return mac_canonize($eui48);
20 daniel-mar 192
        if (($eui48[1] != '0') && ($eui48[1] != '4') && ($eui48[1] != '8') && ($eui48[1] != 'C')) return false; // only allow EUI
16 daniel-mar 193
 
194
        $eui64 = substr($eui48, 0, 6).'FFFE'.substr($eui48, 6, 6);
195
        return mac_canonize($eui64);
196
}
197
 
198
/**
17 daniel-mar 199
 * MAC/EUI-48 to Modified EUI-64 Encapsulation
200
 * @param string $eui48 MAC-48 or EUI-48 address
201
 * @return false|string Modified EUI-64 address
16 daniel-mar 202
 */
17 daniel-mar 203
function maceui48_to_modeui64(string $eui48) {
204
        // Note: MAC-48 is used for network hardware; EUI-48 is used to identify other devices and software.
205
        //       EUI48-to-ModifiedEUI64 Encapsulation uses 0xFFFE middle part (SIC! This was a mistake by IETF, since it should actually be 0xFFFF!)
206
        if (!mac_valid($eui48)) return false;
207
        $eui48 = mac_canonize($eui48, '');
208
        if (eui_bits($eui48) == 64) return mac_canonize($eui48);
20 daniel-mar 209
        if (($eui48[1] != '0') && ($eui48[1] != '4') && ($eui48[1] != '8') && ($eui48[1] != 'C')) return false; // only allow EUI
17 daniel-mar 210
 
211
        $eui64 = substr($eui48, 0, 6).'FFFE'.substr($eui48, 6, 6);
212
 
213
        $eui64[1] = dechex(hexdec($eui64[1]) | 2); // flip seventh bit
214
 
215
        return mac_canonize($eui64);
216
}
217
 
218
/**
19 daniel-mar 219
 * Try to convert IPv6-Link-Local address to MAC-48
220
 * @param string $ipv6 IPv6-Link-Local address
17 daniel-mar 221
 * @return false|string MAC-48 (or IPv6 if it was no LinkLocal address, or Modified EUI-64 if it decapsulation failed)
222
 */
223
function ipv6linklocal_to_mac48(string $ipv6) {
16 daniel-mar 224
        // https://stackoverflow.com/questions/12095835/quick-way-of-expanding-ipv6-addresses-with-php (modified)
23 daniel-mar 225
        $tmp = @inet_pton($ipv6);
16 daniel-mar 226
        if ($tmp === false) return false;
227
        $hex = unpack("H*hex", $tmp);
228
        $ipv6 = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1);
229
 
19 daniel-mar 230
        // Remove "fe80::" to convert IPv6-Link-Local address back to EUI-64
16 daniel-mar 231
        // see https://support.lenovo.com/de/de/solutions/ht509925-how-to-convert-a-mac-address-into-an-ipv6-link-local-address-eui-64
232
        $cnt = 0;
233
        $mac = preg_replace('@^fe80:0000:0000:0000:@i', '', $ipv6, -1, $cnt);
234
        if ($cnt == 0) return false;
235
 
236
        // Set LAA to UAA again
17 daniel-mar 237
        $mac_uaa_64 = $mac;
238
        $mac_uaa_64[1] = dechex(hexdec($mac_uaa_64[1]) & 253);
16 daniel-mar 239
 
17 daniel-mar 240
        $mac_uaa_48 = eui64_to_eui48($mac_uaa_64);
241
        if (eui_bits($mac_uaa_48) == 48) {
242
                return $mac_uaa_48; // Output MAC-48 (UAA)
243
        } else {
244
                return $mac; // Failed decapsulation; output Modified EUI-64 instead
245
        }
16 daniel-mar 246
}
247
 
248
/**
19 daniel-mar 249
 * Converts MAC-48 or EUI-48 to IPv6-Link-Local (based on Modified EUI-64)
15 daniel-mar 250
 * @param string $mac
16 daniel-mar 251
 * @return false|string
252
 */
17 daniel-mar 253
function maceui_to_ipv6linklocal(string $mac) {
16 daniel-mar 254
        if (!mac_valid($mac)) return false;
255
        if (eui_bits($mac) == 48) {
17 daniel-mar 256
                $mac = maceui48_to_modeui64($mac);
16 daniel-mar 257
        }
258
        $mac = mac_canonize($mac, '');
259
        $mac = str_pad($mac, 16, '0', STR_PAD_LEFT);
260
        return strtolower('fe80::'.substr($mac,0, 4).':'.substr($mac,4, 4).':'.substr($mac,8, 4).':'.substr($mac,12, 4));
261
}
262
 
263
/**
20 daniel-mar 264
 * @param string $mac
265
 * @return string
15 daniel-mar 266
 * @throws Exception
267
 */
20 daniel-mar 268
function mac_type(string $mac): string {
17 daniel-mar 269
        // Format MAC for machine readability
270
        $mac = mac_canonize($mac, '');
271
 
25 daniel-mar 272
        /*
20 daniel-mar 273
         *
274
         *      ZYXM
275
         * 0    0000    EUI (OUI)
22 daniel-mar 276
         * 1    0001    [Multicast]
20 daniel-mar 277
         * 2    0010    AAI
22 daniel-mar 278
         * 3    0011    [Multicast]
20 daniel-mar 279
         * 4    0100    EUI (OUI)
22 daniel-mar 280
         * 5    0101    [Multicast]
20 daniel-mar 281
         * 6    0110    Reserved
22 daniel-mar 282
         * 7    0111    [Multicast]
20 daniel-mar 283
         * 8    1000    EUI (OUI)
22 daniel-mar 284
         * 9    1001    [Multicast]
20 daniel-mar 285
         * A    1010    ELI (CID)
22 daniel-mar 286
         * B    1011    [Multicast]
20 daniel-mar 287
         * C    1100    EUI (OUI)
22 daniel-mar 288
         * D    1101    [Multicast]
20 daniel-mar 289
         * E    1110    SAI
22 daniel-mar 290
         * F    1111    [Multicast]
20 daniel-mar 291
         *
292
         */
293
 
16 daniel-mar 294
        $type = '';
20 daniel-mar 295
        $tmp = ipv6linklocal_to_mac48($mac);
296
        if ($tmp !== false) {
297
                $mac = $tmp;
298
                $type = 'IPv6-Link-Local';
299
        }
300
        if (!mac_valid($mac)) throw new Exception("Invalid MAC address");
301
        if ($tmp === false) {
22 daniel-mar 302
                if (($mac[1] == '2') || ($mac[1] == '3')) {
20 daniel-mar 303
                        /*
304
                         * AAI: Administratively Assigned Identifier
305
                         * Administrators who wish to assign local MAC addresses in an
306
                         * arbitrary fashion (for example, randomly) and yet maintain
307
                         * compatibility with other assignment protocols operating under the
308
                         * SLAP on the same LAN may assign a local MAC address as AAI.
309
                         */
310
                        $type = 'AAI-' . eui_bits($mac).' (Administratively Assigned Identifier)';
22 daniel-mar 311
                } else if (($mac[1] == '6') || ($mac[1] == '7')) {
20 daniel-mar 312
                        /*
313
                         * Reserved
314
                         * may be administratively used and assigned in accordance with the
315
                         * considerations specified for AAI usage, without effect on SLAP
316
                         * assignments. However, administrators should be cognizant of
317
                         * possible future specifications… that would render administrative
318
                         * assignment incompatible with the SLAP.
319
                         */
320
                        $type = 'Reserved-' . eui_bits($mac);
22 daniel-mar 321
                } else if (($mac[1] == 'A') || ($mac[1] == 'B')) {
20 daniel-mar 322
                        /*
323
                         * ELI: Extended Local Identifier
324
                         * An ELI is based on a 24 bit CID
325
                         * A CID has ZYXM bits set to 1010 (0b1010 = 0xA)
326
                         * Since X=1 (U/L=1), the CID cannot be used to form a universal UAA MAC (only a local LAA MAC)
327
                         */
328
                        $type = 'ELI-' . eui_bits($mac).' (Extended Local Identifier)';
22 daniel-mar 329
                } else if (($mac[1] == 'E') || ($mac[1] == 'F')) {
20 daniel-mar 330
                        /*
331
                         * SAI: Standard Assigned Identifier
332
                         * Specification of the use of the SAI quadrant for SLAP address
333
                         * assignments is reserved for the standard forthcoming from IEEE
334
                         * P802.1CQ.
335
                         * An SAI is assigned by a protocol specified in an IEEE 802 standard.
336
                         * Multiple protocols for assigning SAI may be specified within various
337
                         * IEEE 802 standards. Coexistence of such protocols may be supported
338
                         * by restricting each to assignments within a subspace of SAI space.
339
                         * In some cases, an SAI assignment protocol may assign the SAI to convey
340
                         * specific information. Such information may be interpreted by receivers
341
                         * and bridges that recognize the specific SAI assignment protocol, as
342
                         * identified by the subspace of the SAI. The functionality of receivers
343
                         * and bridges that do not recognize the protocol is not affected.
344
                         */
345
                        $type = 'SAI-' . eui_bits($mac).' (Standard Assigned Identifier)';
22 daniel-mar 346
                } else {
20 daniel-mar 347
                        /*
348
                         * Extended Unique Identifier
349
                         * Based on an OUI-24, OUI-28, or OUI-36
350
                         */
18 daniel-mar 351
                        if (eui_bits($mac) == 48) {
20 daniel-mar 352
                                // The name "MAC-48" has been deprecated by IEEE
353
                                //$type = 'MAC-48 (network hardware) or EUI-48 (other devices and software)';
354
                                $type = 'EUI-48 (Extended Unique Identifier)';
18 daniel-mar 355
                        } else if (eui_bits($mac) == 64) {
20 daniel-mar 356
                                if (substr($mac, 6, 4) == 'FFFE') {
357
                                        if ((hexdec($mac[1]) & 2) == 2) {
358
                                                $type = 'EUI-64 (Extended Unique Identifier, MAC/EUI-48 to Modified EUI-64 Encapsulation)';
18 daniel-mar 359
                                        } else {
20 daniel-mar 360
                                                $type = 'EUI-64 (Extended Unique Identifier, EUI-48 to EUI-64 Encapsulation)';
18 daniel-mar 361
                                        }
20 daniel-mar 362
                                } else if (substr($mac, 6, 4) == 'FFFF') {
363
                                        $type = 'EUI-64 (Extended Unique Identifier, MAC-48 to EUI-64 Encapsulation)';
17 daniel-mar 364
                                } else {
20 daniel-mar 365
                                        $type = 'EUI-64 (Extended Unique Identifier)';
17 daniel-mar 366
                                }
367
                        } else {
18 daniel-mar 368
                                assert(false); /** @phpstan-ignore-line */
17 daniel-mar 369
                        }
370
                }
16 daniel-mar 371
        }
22 daniel-mar 372
 
373
        if ((hexdec($mac[1])&1) == 1) {
25 daniel-mar 374
                // see also https://networkengineering.stackexchange.com/questions/83121/can-eli-aai-sai-addresses-be-multicast
22 daniel-mar 375
 
376
                /* https://standards.ieee.org/wp-content/uploads/import/documents/tutorials/eui.pdf writes:
377
                 * - The assignee of an OUI or OUI-36 is exclusively authorized to assign group
378
                 *   MAC addresses, with I/G=1, by extending a modified version of the assigned
379
                 *   OUI or OUI-36 in which the M bit is set to 1. Such addresses are not EUIs and
380
                 *   do not globally identify hardware instances, even though U/L=0.
381
                 * - The assignee of a CID may assign local group MAC addresses by extending a modified version of
382
                 *   the assigned CID by setting the M bit to 1 (so that I/G=1). The resulting
383
                 *   extended identifier is an ELI.
384
                 */
385
 
25 daniel-mar 386
                // TODO: If "Multicast EUI" is not an EUI (as tutorials/eui.pdf states), how should we name it instead?!
22 daniel-mar 387
                $type = "Multicast $type";
388
        }
389
 
20 daniel-mar 390
        return $type;
391
}
392
 
393
/**
394
 * Prints information about an IPv6-Link-Local address, MAC, EUI, ELI, AAI, or SAI.
395
 * @param string $mac IPv6-Link-Local address, MAC, EUI, ELI, AAI, or SAI
396
 * @return void
397
 * @throws Exception
398
 */
399
function decode_mac(string $mac) {
22 daniel-mar 400
 
21 daniel-mar 401
        // TODO: Should we decode Multicast MAC to its IP (see https://ipcisco.com/lesson/multicast-mac-addresses/)?
22 daniel-mar 402
 
20 daniel-mar 403
        echo sprintf("%-32s %s\n", "Input:", $mac);
404
 
405
        // Format MAC for machine readability
406
        $mac = mac_canonize($mac, '');
407
 
408
        $type = mac_type($mac);
16 daniel-mar 409
        echo sprintf("%-32s %s\n", "Type:", $type);
15 daniel-mar 410
 
16 daniel-mar 411
        echo "\n";
412
 
25 daniel-mar 413
        $is_eli_unicast = (hexdec($mac[1]) & 0xF) == 0xA;  // ELI = 1010 (unicast)
414
        $is_eli         = (hexdec($mac[1]) & 0xE) == 0xA;  // ELI = 101x (unicast and multicast)
415
 
416
        $is_eui_unicast = (hexdec($mac[1]) & 0x3) == 0x0;  // EUI = xx00 (unicast)
417
        $is_eui         = (hexdec($mac[1]) & 0x2) == 0x0;  // EUI = xx0x (unicast and multicast)
418
 
16 daniel-mar 419
        // Show various representations
25 daniel-mar 420
        if ($is_eli) {
20 daniel-mar 421
                // Note: There does not seem to exist an algorithm for encapsulating/converting ELI-48 <=> ELI-64
18 daniel-mar 422
                echo sprintf("%-32s %s\n", "ELI-".eui_bits($mac).":", mac_canonize($mac));
19 daniel-mar 423
                $mac48 = eui64_to_eui48($mac);
424
                echo sprintf("%-32s %s\n", "MAC-48 (Local):", (eui_bits($mac48) != 48) ? 'Not available' : $mac48);
25 daniel-mar 425
        } else if ($is_eui) {
18 daniel-mar 426
                $eui48 = eui64_to_eui48($mac);
19 daniel-mar 427
                echo sprintf("%-32s %s\n", "EUI-48 or MAC-48:", (eui_bits($eui48) != 48) ? 'Not available' : $eui48);
18 daniel-mar 428
                if (eui_bits($mac) == 48) {
429
                        $eui64 = mac48_to_eui64($mac);
430
                        echo sprintf("%-32s %s\n", "EUI-64:", ((eui_bits($eui64) != 64) ? 'Not available' : $eui64).' (MAC-48 to EUI-64 Encapsulation)');
431
                        $eui64 = eui48_to_eui64($mac);
432
                        echo sprintf("%-32s %s\n", "", ((eui_bits($eui64) != 64) ? 'Not available' : $eui64).' (EUI-48 to EUI-64 Encapsulation)');
433
                        $eui64 = maceui48_to_modeui64($mac);
434
                        echo sprintf("%-32s %s\n", "", ((eui_bits($eui64) != 64) ? 'Not available' : $eui64).' (MAC/EUI-48 to Modified EUI-64 Encapsulation)');
435
                        $ipv6 = maceui_to_ipv6linklocal($mac);
19 daniel-mar 436
                        echo sprintf("%-32s %s\n", "IPv6-Link-Local address:", $ipv6);
18 daniel-mar 437
                } else {
438
                        $eui64 = mac_canonize($mac);
439
                        echo sprintf("%-32s %s\n", "EUI-64:", $eui64);
440
                }
17 daniel-mar 441
        }
2 daniel-mar 442
 
443
        // Vergabestelle
444
        $ul = hexdec($mac[1]) & 2; // Bit #LSB+1 of Byte 1
445
        $ul_ = ($ul == 0) ? '[0] Universally Administered Address (UAA)' : '[1] Locally Administered Address (LAA)';
15 daniel-mar 446
        echo sprintf("%-32s %s\n", "Administration type (U/L flag):", $ul_);
2 daniel-mar 447
 
16 daniel-mar 448
        // Empfaengergruppe
449
        $ig = hexdec($mac[1]) & 1; // Bit #LSB+0 of Byte 1
18 daniel-mar 450
        $ig_ = ($ig == 0) ? '[0] Unicast (Individual)' : '[1] Multicast (Group)';
16 daniel-mar 451
        echo sprintf("%-32s %s\n", "Transmission type (I/G flag):", $ig_);
452
 
2 daniel-mar 453
        // Query IEEE registries
17 daniel-mar 454
        if (count(glob(IEEE_MAC_REGISTRY.DIRECTORY_SEPARATOR.'*.txt')) > 0) {
22 daniel-mar 455
                $alt_mac = $mac;
25 daniel-mar 456
                $alt_mac[1] = dechex(hexdec($alt_mac[1])^1); // switch Unicast<=>Multicast in order to find the vendor
22 daniel-mar 457
 
25 daniel-mar 458
                if (is_dir(IEEE_MAC_REGISTRY)) {
459
                        if ($is_eli) {
460
                                // Query the CID registry
461
                                if (
462
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'cid.txt', 'CID', $mac)) ||
463
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'cid.txt', 'CID', $alt_mac))
464
                                ) {
465
                                        echo "\n";
466
                                        echo $x;
467
                                } else {
468
                                        $registry_name = 'CID';
469
                                        echo "\n";
470
                                        echo sprintf("%-32s 0x%s\n", "IEEE $registry_name:", substr($mac, 0, 6));
471
                                        echo sprintf("%-32s 0x%s\n", "Vendor-specific part:", substr($mac, 6));
472
                                        echo sprintf("%-32s %s\n", "Registrant:", "$registry_name not found in database");
473
                                }
474
                        } else if ($is_eui) {
475
                                // Query the OUI registries
476
                                if (
477
                                        # The IEEE Registration Authority distinguishes between IABs and OUI-36 values. Both are 36-bit values which may be used to generate EUI-48 values, but IABs may not be used to generate EUI-64 values.[6]
478
                                        # Note: The Individual Address Block (IAB) is an inactive registry activity, which has been replaced by the MA-S registry product as of January 1, 2014.
479
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'iab.txt', 'IAB', $mac)) ||
480
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'oui36.txt', 'OUI-36 (MA-S)', $mac)) ||
481
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'mam.txt', '28 bit identifier (MA-M)', $mac)) ||
482
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'oui.txt', 'OUI (MA-L)', $mac)) ||
483
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'iab.txt', 'IAB', $alt_mac)) ||
484
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'oui36.txt', 'OUI-36 (MA-S)', $alt_mac)) ||
485
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'mam.txt', '28 bit identifier (MA-M)', $alt_mac)) ||
486
                                        ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'oui.txt', 'OUI (MA-L)', $alt_mac))
487
                                ) {
488
                                        echo "\n";
489
                                        echo $x;
490
                                } else {
491
                                        $registry_name = 'OUI (MA-L)?';
492
                                        echo "\n";
493
                                        echo sprintf("%-32s 0x%s\n", "IEEE $registry_name:", substr($mac, 0, 6));
494
                                        echo sprintf("%-32s 0x%s\n", "Vendor-specific part:", substr($mac, 6));
495
                                        echo sprintf("%-32s %s\n", "Registrant:", "$registry_name not found in database");
496
 
497
                                        $registry_name = '28 bit identifier (MA-M)?';
498
                                        echo "\n";
499
                                        echo sprintf("%-32s 0x%s\n", "IEEE $registry_name:", substr($mac, 0, 7));
500
                                        echo sprintf("%-32s 0x%s\n", "Vendor-specific part:", substr($mac, 7));
501
                                        echo sprintf("%-32s %s\n", "Registrant:", "$registry_name not found in database");
502
 
503
                                        $registry_name = 'OUI-36 (MA-S)?';
504
                                        echo "\n";
505
                                        echo sprintf("%-32s 0x%s\n", "IEEE $registry_name:", substr($mac, 0, 9));
506
                                        echo sprintf("%-32s 0x%s\n", "Vendor-specific part:", substr($mac, 9));
507
                                        echo sprintf("%-32s %s\n", "Registrant:", "$registry_name not found in database");
508
                                }
18 daniel-mar 509
                        }
15 daniel-mar 510
                }
2 daniel-mar 511
        }
512
 
15 daniel-mar 513
        $vm = '';
514
        // === FAQ "Detection rules which don't have their dedicated page yet" ===
515
        // https://wiki.xenproject.org/wiki/Xen_Networking
516
        // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
517
        // https://www.techrepublic.com/blog/data-center/mac-address-scorecard-for-common-virtual-machine-platforms
518
        if (mac_between($mac, '00:16:3E:00:00:00', '00:16:3E:FF:FF:FF')) $vm = "Red Hat Xen, XenSource, Novell Xen";
519
        // http://techgenix.com/mac-address-pool-duplication-hyper-v/
520
        // https://docs.microsoft.com/en-us/system-center/vmm/network-mac?view=sc-vmm-1807
521
        // https://blogs.technet.microsoft.com/gbanin/2014/08/27/how-to-solve-mac-address-conflict-on-hyper-v/
522
        if (mac_between($mac, '00:1D:D8:B7:1C:00', '00:1D:D8:F4:1F:FF')) $vm = "Microsoft SCVMM (System Center Virtual Machine Manager)";
523
        // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
524
        // https://www.techrepublic.com/blog/data-center/mac-address-scorecard-for-common-virtual-machine-platforms/
525
        // https://blogs.technet.microsoft.com/medv/2011/01/24/how-to-manage-vm-mac-addresses-with-the-globalimagedata-xml-file-in-med-v-v1/
526
        if (mac_between($mac, '00:03:FF:00:00:00', '00:03:FF:FF:FF:FF')) $vm = "Microsoft Virtual PC / Virtual Server";
527
        // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
528
        if (mac_between($mac, '00:18:51:00:00:00', '00:18:51:FF:FF:FF')) $vm = "SWsoft";
529
        // https://macaddress.io/statistics/company/17619
530
        if (mac_between($mac, '58:9C:FC:00:00:00', '58:9C:FC:FF:FF:FF')) $vm = "bhyve by FreebsdF";
531
        // https://macaddress.io/statistics/company/17388
532
        if (mac_between($mac, '50:6B:8D:00:00:00', '50:6B:8D:FF:FF:FF')) $vm = "Nutanix AHV";
533
        // https://www.centos.org/forums/viewtopic.php?t=26739
534
        if (mac_between($mac, '54:52:00:00:00:00', '54:52:FF:FF:FF:FF')) $vm = "KVM (proxmox)";
535
        // Self tested (alldatafeeds.com)
536
        if (mac_between($mac, '96:00:00:00:00:00', '96:00:FF:FF:FF:FF')) $vm = "Hetzner vServer (based on KVM and libvirt)";
537
        // === FAQ "How to recognise a VMware's virtual machine by its MAC address?" ===
538
        if (mac_between($mac, '00:50:56:00:00:00', '00:50:56:FF:FF:FF')) $vm = "VMware vSphere, VMware Workstation, VMware ESX Server";
539
        if (mac_between($mac, '00:50:56:80:00:00', '00:50:56:BF:FF:FF')) $vm = "VMware vSphere managed by vCenter Server";
540
        if (mac_between($mac, '00:0C:29:00:00:00', '00:0C:29:FF:FF:FF')) $vm = "VMWare Standalone VMware vSphere, VMware Workstation, VMware Horizon";
541
        if (mac_between($mac, '00:05:69:00:00:00', '00:05:69:FF:FF:FF')) $vm = "VMware ESX, VMware GSX Server";
542
        if (mac_between($mac, '00:1C:14:00:00:00', '00:1C:14:FF:FF:FF')) $vm = "VMWare";
543
        // === FAQ "machine by its MAC address?" ===
544
        if (mac_between($mac, '00:1C:42:00:00:00', '00:1C:42:FF:FF:FF')) $vm = "Parallels Virtual Machine";
545
        // === FAQ "How to recognise a Docker container by its MAC address?" ===
546
        if (mac_between($mac, '02:42:00:00:00:00', '02:42:FF:FF:FF:FF')) $vm = "Docker container";
547
        // === FAQ =How to recognise a Microsoft Hyper-V's virtual machine by its MAC address?" ===
548
        if (mac_between($mac, '00:15:5D:00:00:00', '00:15:5D:FF:FF:FF')) $vm = "Microsoft Hyper-V";
549
        // === FAQ "How to recognise an Oracle Virtual machine by its MAC address?" ===
550
        if (mac_between($mac, '08:00:27:00:00:00', '08:00:27:FF:FF:FF')) $vm = "Oracle VirtualBox 5.2"; // Pcs Systemtechnik GmbH
551
        if (mac_between($mac, '52:54:00:00:00:00', '52:54:00:FF:FF:FF')) $vm = "Oracle VirtualBox 5.2 + Vagrant"; // 52:54:00 (Exact MAC: 52:54:00:C9:C7:04)
552
        if (mac_between($mac, '00:21:F6:00:00:00', '00:21:F6:FF:FF:FF')) $vm = "Oracle VirtualBox 3.3";
553
        if (mac_between($mac, '00:14:4F:00:00:00', '00:14:4F:FF:FF:FF')) $vm = "Oracle VM Server for SPARC";
554
        if (mac_between($mac, '00:0F:4B:00:00:00', '00:0F:4B:FF:FF:FF')) $vm = "Oracle Virtual Iron 4";
2 daniel-mar 555
 
15 daniel-mar 556
        if ($vm) {
557
                echo sprintf("%-32s %s\n", "Special use:", "Virtual machine $vm");
558
        }
2 daniel-mar 559
 
15 daniel-mar 560
        $app = '';
561
 
562
        // === FAQ "Other MAC address applications"
563
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
564
        // https://tools.ietf.org/html/rfc1060
565
        if (mac_between($mac, '03:00:00:01:00:00', '03:00:40:00:00:00')) $app = 'User-defined (per 802 spec), EtherType is 0x0802';
566
        if (mac_equals($mac, '01:00:1D:00:00:00')) $app = 'Cabletron PC-OV PC discover (on demand), EtherType is 0x0802';
567
        if (mac_equals($mac, '01:00:1D:42:00:00')) $app = 'Cabletron PC-OV Bridge discover (on demand), EtherType is 0x0802';
568
        if (mac_equals($mac, '01:00:1D:52:00:00')) $app = 'Cabletron PC-OV MMAC discover (on demand), EtherType is 0x0802';
569
        if (mac_between($mac, '01:00:3C:00:00:00' , '01:00:3C:FF:FF:FF')) $app = 'Auspex Systems (Serverguard)';
570
        if (mac_equals($mac, '01:00:10:00:00:20')) $app = 'Hughes Lan Systems Terminal Server S/W download, EtherType is 0x0802';
571
        if (mac_equals($mac, '01:00:10:FF:FF:20')) $app = 'Hughes Lan Systems Terminal Server S/W request, EtherType is 0x0802';
572
        if (mac_equals($mac, '01:00:81:00:00:00')) $app = 'Synoptics Network Management';
573
        if (mac_equals($mac, '01:00:81:00:00:02')) $app = 'Synoptics Network Management';
574
        if (mac_equals($mac, '01:00:81:00:01:00')) $app = 'Bay Networks (Synoptics) autodiscovery, EtherType is 0x0802 SNAP type is 0x01A2';
575
        if (mac_equals($mac, '01:00:81:00:01:01')) $app = 'Bay Networks (Synoptics) autodiscovery, EtherType is 0x0802 SNAP type is 0x01A1';
576
        if (mac_between($mac, '01:20:25:00:00:00', '01:20:25:7F:FF:FF')) $app = 'Control Technology Inc\'s Industrial Ctrl Proto., EtherType is 0x873A';
577
        if (mac_equals($mac, '01:80:24:00:00:00')) $app = 'Kalpana Etherswitch every 60 seconds, EtherType is 0x0802';
578
        if (mac_equals($mac, '01:DD:00:FF:FF:FF')) $app = 'Ungermann-Bass boot-me requests, EtherType is 0x7002';
579
        if (mac_equals($mac, '01:DD:01:00:00:00')) $app = 'Ungermann-Bass Spanning Tree, EtherType is 0x7005';
580
        if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'OS/2 1.3 EE + Communications Manager, EtherType is 0x80D5';
581
        if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'OS/2 1.3 EE + Communications Manager, EtherType is 0x80D5';
582
        if (mac_equals($mac, '03:00:00:00:01:00')) $app = 'OSI All-IS Multicast, EtherType is 0x0802';
583
        if (mac_equals($mac, '03:00:00:00:02:00')) $app = 'OSI All-ES Multicast, EtherType is 0x0802';
584
        if (mac_equals($mac, '03:00:00:80:00:00')) $app = 'Discovery Client, EtherType is 0x0802';
585
        if (mac_equals($mac, '03:00:FF:FF:FF:FF')) $app = 'All Stations address, EtherType is 0x0802';
586
        if (mac_between($mac, '09:00:0D:00:00:00', '09:00:0D:FF:FF:FF')) $app = 'ICL Oslan Multicast, EtherType is 0x0802';
587
        if (mac_equals($mac, '09:00:0D:02:00:00')) $app = 'ICL Oslan Service discover only on boot';
588
        if (mac_equals($mac, '09:00:0D:02:0A:3C')) $app = 'ICL Oslan Service discover only on boot';
589
        if (mac_equals($mac, '09:00:0D:02:0A:38')) $app = 'ICL Oslan Service discover only on boot';
590
        if (mac_equals($mac, '09:00:0D:02:0A:39')) $app = 'ICL Oslan Service discover only on boot';
591
        if (mac_equals($mac, '09:00:0D:02:FF:FF')) $app = 'ICL Oslan Service discover only on boot';
592
        if (mac_equals($mac, '09:00:0D:09:00:00')) $app = 'ICL Oslan Service discover as required';
593
        if (mac_equals($mac, '09:00:1E:00:00:00')) $app = 'Apollo DOMAIN, EtherType is 0x8019';
594
        if (mac_equals($mac, '09:00:02:04:00:01')) $app = 'Vitalink printer messages, EtherType is 0x8080';
595
        if (mac_equals($mac, '09:00:02:04:00:02')) $app = 'Vitalink bridge management, EtherType is 0x8080';
596
        if (mac_equals($mac, '09:00:4C:00:00:0F')) $app = 'BICC Remote bridge adaptive routing (e.g. to Retix), EtherType is 0x0802';
597
        if (mac_equals($mac, '09:00:4E:00:00:02')) $app = 'Novell IPX, EtherType is 0x8137';
598
        if (mac_equals($mac, '09:00:6A:00:01:00')) $app = 'TOP NetBIOS';
599
        if (mac_equals($mac, '09:00:7C:01:00:01')) $app = 'Vitalink DLS Multicast';
600
        if (mac_equals($mac, '09:00:7C:01:00:03')) $app = 'Vitalink DLS Inlink';
601
        if (mac_equals($mac, '09:00:7C:01:00:04')) $app = 'Vitalink DLS and non DLS Multicast';
602
        if (mac_equals($mac, '09:00:7C:02:00:05')) $app = 'Vitalink diagnostics, EtherType is 0x8080';
603
        if (mac_equals($mac, '09:00:7C:05:00:01')) $app = 'Vitalink gateway, EtherType is 0x8080';
604
        if (mac_equals($mac, '09:00:7C:05:00:02')) $app = 'Vitalink Network Validation Message';
605
        if (mac_equals($mac, '09:00:09:00:00:01')) $app = 'HP Probe, EtherType is 0x8005 or 0x0802';
606
        if (mac_equals($mac, '09:00:09:00:00:04')) $app = 'HP DTC, EtherType is 0x8005';
607
        if (mac_equals($mac, '09:00:26:01:00:01')) $app = 'Vitalink TransLAN bridge management, EtherType is 0x8038';
608
        if (mac_equals($mac, '09:00:39:00:70:00')) $app = 'Spider Systems Bridge';
609
        if (mac_between($mac, '09:00:56:00:00:00', '09:00:56:FE:FF:FF')) $app = 'Stanford reserved';
610
        if (mac_between($mac, '09:00:56:FF:00:00', '09:00:56:FF:FF:FF')) $app = 'Stanford V Kernel, version 6.0, EtherType is 0x805C';
611
        if (mac_equals($mac, '09:00:77:00:00:00')) $app = 'Retix Bridge Local Management System, EtherType is 0x0802';
612
        if (mac_equals($mac, '09:00:77:00:00:01')) $app = 'Retix spanning tree bridges, EtherType is 0x0802';
613
        if (mac_equals($mac, '09:00:77:00:00:02')) $app = 'Retix Bridge Adaptive routing, EtherType is 0x0802';
614
        if (mac_equals($mac, '09:00:87:80:FF:FF')) $app = 'Xyplex Terminal Servers, EtherType is 0x0889';
615
        if (mac_equals($mac, '09:00:87:90:FF:FF')) $app = 'Xyplex Terminal Servers, EtherType is 0x0889';
616
        if (mac_between($mac, '44:38:39:FF:00:00', '44:38:39:FF:FF:FF')) $app = 'Multi-Chassis Link Aggregation (Cumulus Linux)';
617
        if (mac_equals($mac, 'FF:FF:00:40:00:01')) $app = 'LANtastic, EtherType is 0x81D6';
618
        if (mac_equals($mac, 'FF:FF:00:60:00:04')) $app = 'LANtastic, EtherType is 0x81D6';
619
        if (mac_equals($mac, 'FF:FF:01:E0:00:04')) $app = 'LANtastic';
620
 
621
        // === FAQ "The "CF" series MAC addresses" ===
622
        // https://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml
623
        // https://tools.ietf.org/html/rfc2153
624
        // https://tools.ietf.org/html/rfc7042#section-2.3.2
625
        if (mac_between($mac, 'CF:00:00:00:00:00', 'CF:00:00:FF:FF:FF')) $app = 'Reserved';
626
        if (mac_equals($mac, 'CF:00:00:00:00:00')) $app = 'Used for Ethernet loopback tests';
627
 
628
        // === FAQ "How to recognise a Broadcast MAC address application?" ===
19 daniel-mar 629
        // According to https://standards.ieee.org/wp-content/uploads/import/documents/tutorials/eui.pdf FFFFFFFFFFFF can be used as NULL EUI
630
        if (mac_equals($mac, 'FF:FF:FF:FF:FF:FF')) echo sprintf("%-32s %s\n", "Special use:", "Broadcast messaging or Null-EUI");
15 daniel-mar 631
 
632
        // === FAQ "How to recognise a Virtual Router ID by MAC address?" ===
633
        // https://tools.ietf.org/html/rfc7042#section-5.1
634
        // https://tools.ietf.org/html/rfc5798
635
        if (mac_between($mac, '00:00:5E:00:01:00', '00:00:5E:00:01:FF')) $app = 'IPv4 Virtual Router Redundancy Protocol  (VRRP)';
636
        if (mac_between($mac, '00:00:5E:00:02:00', '00:00:5E:00:02:FF')) $app = 'IPv6 Virtual Router Redundancy Protocol';
637
 
638
        // === FAQ "How to recognise an IP frame by MAC address?" ===
639
        // https://tools.ietf.org/html/rfc1060
640
        // https://en.wikipedia.org/wiki/Multicast_address#cite_note-15
641
        // https://tools.ietf.org/html/rfc2464
642
        // https://www.iana.org/go/rfc1112
643
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
644
        if (mac_between($mac, '01:00:5E:00:00:00', '01:00:5E:7F:FF:FF')) $app = 'IPv4 Multicast (EtherType is 0x0800)';
645
        if (mac_between($mac, '33:33:00:00:00:00', '33:33:FF:FF:FF:FF')) $app = 'IPv6 Multicast. IPv6 neighbor discovery (EtherType is 0x86DD)'; // TODO: Dabei werden die untersten 32 Bit der IPv6-Multicast-Adresse in die MAC-Adresse eingebettet.
646
        if (mac_between($mac, '00:00:5E:00:52:13', '00:00:5E:00:52:13')) $app = 'Proxy Mobile IPv6';
16 daniel-mar 647
        if (mac_between($mac, '00:00:5E:FE:C0:00:02:00', '00:00:5E:FE:C0:00:02:FF')) $app = 'IPv4 derived documentation';
648
        if (mac_between($mac, '00:00:5E:FE:C6:33:64:00', '00:00:5E:FE:C6:33:64:FF')) $app = 'IPv4 derived documentation';
649
        if (mac_between($mac, '00:00:5E:FE:CB:00:71:00', '00:00:5E:FE:CB:00:71:FF')) $app = 'IPv4 derived documentation';
650
        if (mac_equals($mac, '00:00:5E:FE:EA:C0:00:02')) $app = 'IPv4 multicast derived documentation';
651
        if (mac_equals($mac, '00:00:5E:FE:EA:C6:33:64')) $app = 'IPv4 multicast derived documentation';
652
        if (mac_equals($mac, '00:00:5E:FE:EA:CB:00:71')) $app = 'IPv4 multicast derived documentation';
653
        if (mac_between($mac, '01:00:5E:FE:C0:00:02:00', '01:00:5E:FE:C0:00:02:FF')) $app = 'IPv4 derived documentation';
654
        if (mac_between($mac, '01:00:5E:FE:C6:33:64:00', '01:00:5E:FE:C6:33:64:FF')) $app = 'IPv4 derived documentation';
655
        if (mac_between($mac, '01:00:5E:FE:CB:00:71:00', '01:00:5E:FE:CB:00:71:FF')) $app = 'IPv4 derived documentation';
656
        if (mac_equals($mac, '01:00:5E:FE:EA:C0:00:02')) $app = 'IPv4 multicast derived documentation';
657
        if (mac_equals($mac, '01:00:5E:FE:EA:C6:33:64')) $app = 'IPv4 multicast derived documentation';
658
        if (mac_equals($mac, '01:00:5E:FE:EA:CB:00:71')) $app = 'IPv4 multicast derived documentation';
15 daniel-mar 659
        if (mac_between($mac, '01:80:C2:00:00:20', '01:80:C2:00:00:2F')) $app = 'Reserved for use by Multiple Registration Protocol (MRP) applications';
16 daniel-mar 660
        if (mac_between($mac, '02:00:5E:FE:00:00:00:00', '02:00:5E:FE:FF:FF:FF:FF')) $app = 'IPv4 Addr Holders';
15 daniel-mar 661
        if (mac_equals($mac, '03:00:00:20:00:00')) $app = 'IP multicast address';
662
        if (mac_equals($mac, 'C0:00:00:04:00:00')) $app = 'IP multicast address';
16 daniel-mar 663
        if (mac_between($mac, '03:00:5E:FE:00:00:00:00', '03:00:5E:FE:FF:FF:FF:FF')) $app = 'IPv4 Addr Holders';
15 daniel-mar 664
 
665
        // === FAQ "How to recognise a MPLS multicast frame by MAC address?" ===
666
        // http://www.iana.org/go/rfc5332
667
        // http://www.iana.org/go/rfc7213
668
        if (mac_between($mac, '01:00:5E:80:00:00', '01:00:5E:8F:FF:FF')) $app = 'MPLS multicast (EtherType is 0x8847 or 0x8848)';
669
        if (mac_equals($mac, '01:00:5E:90:00:00')) $app = 'MPLS-TP p2p';
670
 
671
        // === FAQ "How to recognise a Bidirectional Forwarding Detection (BFD) on Link Aggregation Group (LAG) interfaces by MAC address?" ===
672
        // http://www.iana.org/go/rfc7130
673
        if (mac_equals($mac, '01:00:5E:90:00:01')) $app = 'Bidirectional Forwarding Detection (BFD) on Link Aggregation Group (LAG) interfaces';
674
 
675
        // === FAQ "How to recognise Token Ring specific functions by MAC address?" ===
676
        // https://tools.ietf.org/html/rfc1060
677
        // https://tools.ietf.org/html/rfc1469
678
        // https://standards.ieee.org/products-services/regauth/grpmac/public.html
679
        // https://tools.ietf.org/html/rfc2470
680
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
681
        if (mac_equals($mac, '03:00:00:00:00:01')) $app = 'NetBIOS (Token Ring)';
682
        if (mac_equals($mac, '03:00:00:00:00:02')) $app = 'Locate - Directory Server (Token Ring)';
683
        if (mac_equals($mac, '03:00:00:00:00:04')) $app = 'Synchronous Bandwidth Manager (Token Ring)';
684
        if (mac_equals($mac, '03:00:00:00:00:08')) $app = 'Configuration Report Server (Token Ring)';
685
        if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'Ring Error Monitor (Token Ring)';
686
        if (mac_equals($mac, '03:00:00:00:00:20')) $app = 'Network Server Heartbeat (Token Ring)';
687
        if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'Ring Parameter Monitor (Token Ring)';
688
        if (mac_equals($mac, '03:00:00:00:00:80')) $app = 'Active Monitor (Token Ring)';
689
        if (mac_equals($mac, '03:00:00:00:04:00')) $app = 'LAN Manager (Token Ring)';
690
        if (mac_equals($mac, '03:00:00:00:08:00')) $app = 'Ring Wiring Concentrator (Token Ring)';
691
        if (mac_equals($mac, '03:00:00:00:10:00')) $app = 'LAN Gateway (Token Ring)';
692
        if (mac_equals($mac, '03:00:00:00:20:00')) $app = 'Ring Authorization Server (Token Ring)';
693
        if (mac_equals($mac, '03:00:00:00:40:00')) $app = 'IMPL Server (Token Ring)';
694
        if (mac_equals($mac, '03:00:00:00:80:00')) $app = 'Bridge (Token Ring)';
695
        if (mac_equals($mac, '03:00:00:20:00:00')) $app = 'Single Token-Ring functional address';
696
        if (mac_equals($mac, '03:00:00:00:00:08')) $app = 'Configuration Report Server (CRS) MAC Group address';
697
        if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'Ring Error Monitor (REM) MAC Group address';
698
        if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'Ring Parameter Server (RPS) MAC group address';
699
        if (mac_equals($mac, '03:00:00:00:01:00')) $app = 'All Intermediate System Network Entities address';
700
        if (mac_equals($mac, '03:00:00:00:02:00')) $app = 'All End System Network Entities address, and Lobe Media Test (LMT) MAC group address';
701
        if (mac_equals($mac, '03:00:00:00:04:00')) $app = 'Generic address for all Manager Stations';
702
        if (mac_equals($mac, '03:00:00:00:08:00')) $app = 'All CONs SNARES address';
703
        if (mac_equals($mac, '03:00:00:00:10:00')) $app = 'All CONs End System address';
704
        if (mac_equals($mac, '03:00:00:00:20:00')) $app = 'Loadable Device Generic address';
705
        if (mac_equals($mac, '03:00:00:00:40:00')) $app = 'Load Server Generic address';
706
        if (mac_equals($mac, '03:00:00:40:00:00')) $app = 'Generic address for all Agent Stations';
707
        if (mac_equals($mac, 'C0:00:00:04:00:00')) $app = 'Single Token-Ring functional address';
708
        if (mac_equals($mac, '03:00:80:00:00:00')) $app = 'IPv6 multicast over Token Ring: all-Nodes (FF01::1 and FF02::1) and solicited node (FF02:0:0:0:0:1:FFXX:XXXX) addresses';
709
        if (mac_equals($mac, '03:00:40:00:00:00')) $app = 'IPv6 multicast over Token Ring: all-Routers addresses (FF0X::2)';
710
        if (mac_equals($mac, '03:00:00:80:00:00')) $app = 'IPv6 multicast over Token Ring: any other multicast address with three least significant bits = 000';
711
        if (mac_equals($mac, '03:00:00:40:00:00')) $app = 'IPv6 multicast over Token Ring: any other multicast address with three least significant bits = 001';
712
        if (mac_equals($mac, '03:00:00:20:00:00')) $app = 'IPv6 multicast over Token Ring: any other multicast address with three least significant bits = 010';
713
        if (mac_equals($mac, '03:00:00:10:00:00')) $app = 'IPv6 multicast over Token Ring: any other multicast address with three least significant bits = 011';
714
        if (mac_equals($mac, '03:00:00:08:00:00')) $app = 'IPv6 multicast over Token Ring: any other multicast address with three least significant bits = 100';
715
        if (mac_equals($mac, '03:00:00:04:00:00')) $app = 'IPv6 multicast over Token Ring: any other multicast address with three least significant bits = 101';
716
        if (mac_equals($mac, '03:00:00:02:00:00')) $app = 'IPv6 multicast over Token Ring: any other multicast address with three least significant bits = 110';
717
        if (mac_equals($mac, '03:00:00:01:00:00')) $app = 'IPv6 multicast over Token Ring: any other multicast address with three least significant bits = 111';
718
 
719
        // === FAQ "How to recognise an AppleTalk protocols by MAC address?" ===
720
        // https://tools.ietf.org/html/rfc1060
721
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
722
        if (mac_between($mac, '09:00:07:00:00:00', '09:00:07:00:00:FC')) $app = 'AppleTalk zone multicast addresses (EtherType is 0x0802)';
723
        if (mac_equals($mac, '09:00:07:FF:FF:FF')) $app = 'AppleTalk broadcast address (EtherType is 0x0802)';
724
 
725
        // === FAQ "How to recognise a TRILL protocols by MAC address?" ===
726
        // http://www.iana.org/go/rfc7455
727
        // https://tools.ietf.org/html/draft-ietf-trill-oam-framework-04
728
        // https://standards.ieee.org/products-services/regauth/grpmac/public.html
729
        // https://tools.ietf.org/html/rfc7455#appendix-C
730
        if (mac_between($mac, '00:00:5E:90:01:00', '00:00:5E:90:01:00')) $app = 'TRILL OAM';
731
        if (mac_equals($mac, '01:00:5E:90:01:00')) $app = 'TRILL OAM';
732
        if (mac_between($mac, '01:80:C2:00:00:40', '01:80:C2:00:00:4F')) $app = 'Group MAC addresses used by the TRILL protocols';
733
 
734
        // === FAQ "How to recognise an IEEE 802.1X MAC address application?" ===
735
        if (mac_between($mac, '01:0C:CD:01:00:00', '01:0C:CD:01:01:FF')) $app = 'IEC 61850-8-1 GOOSE Type 1/1A, EtherType is 0x88B8';
736
        if (mac_between($mac, '01:0C:CD:02:00:00', '01:0C:CD:02:01:FF')) $app = 'GSSE (IEC 61850 8-1), EtherType is 0x88B9';
737
        if (mac_between($mac, '01:0C:CD:04:00:00', '01:0C:CD:04:01:FF')) $app = 'Multicast sampled values (IEC 61850 8-1), EtherType is 0x88BA';
738
        if (mac_equals($mac, '01:1B:19:00:00:00')) $app = 'General group address - An 802.1Q VLAN Bridge would forward the frame unchanged.';
739
        if (mac_equals($mac, '01:1B:19:00:00:00')) $app = 'Precision Time Protocol (PTP) version 2 over Ethernet, EtherType is 0x88F7';
740
        if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Bridge Group address Nearest Customer Bridge group address';
741
        if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Spanning Tree Protocol (for bridges) IEEE 802.1D, EtherType is 0x0802';
742
        if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
743
        if (mac_between($mac, '01:80:C2:00:00:00', '01:80:C2:00:00:0F')) $app = 'The initial bridging/link protocols block';
744
        if (mac_between($mac, '01:80:C2:00:00:00', '01:80:C2:00:00:0F')) $app = 'IEEE 802.1D MAC Bridge Filtered MAC Group Addresses';
745
        if (mac_between($mac, '01:80:C2:00:00:00', '01:80:C2:00:00:0F')) $app = 'IEEE Pause, 802.3x';
746
        if (mac_equals($mac, '01:80:C2:00:00:0A')) $app = 'Reserved for future standardization';
747
        if (mac_equals($mac, '01:80:C2:00:00:0B')) $app = 'EDE-SS PEP Address';
748
        if (mac_equals($mac, '01:80:C2:00:00:0C')) $app = 'Reserved for future standardization';
749
        if (mac_equals($mac, '01:80:C2:00:00:0D')) $app = 'Provider Bridge MVRP address';
750
        if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Individual LAN Scope group address, It is intended that no IEEE 802.1 relay device will be defined that will forward frames that carry this destination address';
751
        if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Nearest Bridge group address';
752
        if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
753
        if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Precision Time Protocol (PTP) version 2 over Ethernet, EtherType is 0x88F7';
754
        if (mac_equals($mac, '01:80:C2:00:00:01')) $app = 'IEEE MAC-specific Control Protocols group address';
755
        if (mac_equals($mac, '01:80:C2:00:00:01')) $app = 'Ethernet flow control (Pause frame) IEEE 802.3x, EtherType is 0x8808';
756
        if (mac_equals($mac, '01:80:C2:00:00:1A')) $app = 'Generic Address for All Agent Stations';
757
        if (mac_equals($mac, '01:80:C2:00:00:1B')) $app = 'All Multicast Capable End Systems address';
758
        if (mac_equals($mac, '01:80:C2:00:00:1C')) $app = 'All Multicast Announcements address';
759
        if (mac_equals($mac, '01:80:C2:00:00:1D')) $app = 'All Multicast Capable Intermediate Systems address';
760
        if (mac_equals($mac, '01:80:C2:00:00:1E')) $app = 'All DTR Concentrators MAC group address';
761
        if (mac_equals($mac, '01:80:C2:00:00:1F')) $app = 'EDE-CC PEP Address';
762
        if (mac_between($mac, '01:80:C2:00:00:01', '01:80:C2:00:00:0F')) $app = '802.1 alternate Spanning multicast, EtherType is 0x0802';
763
        if (mac_equals($mac, '01:80:C2:00:00:02')) $app = 'Ethernet OAM Protocol IEEE 802.3ah (also known as "slow protocols"), EtherType is 0x8809';
764
        if (mac_equals($mac, '01:80:C2:00:00:03')) $app = 'Nearest non-TPMR Bridge group address IEEE Std 802.1X PAE address';
765
        if (mac_equals($mac, '01:80:C2:00:00:03')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
766
        if (mac_equals($mac, '01:80:C2:00:00:04')) $app = 'IEEE MAC-specific Control Protocols group address';
767
        if (mac_equals($mac, '01:80:C2:00:00:05')) $app = 'Reserved for future standardization';
768
        if (mac_equals($mac, '01:80:C2:00:00:06')) $app = 'Reserved for future standardization';
769
        if (mac_equals($mac, '01:80:C2:00:00:07')) $app = 'MEF Forum ELMI protocol group address';
770
        if (mac_equals($mac, '01:80:C2:00:00:08')) $app = 'Provider Bridge group address';
771
        if (mac_equals($mac, '01:80:C2:00:00:08')) $app = 'Spanning Tree Protocol (for provider bridges) IEEE 802.1ad, EtherType is 0x0802';
772
        if (mac_equals($mac, '01:80:C2:00:00:09')) $app = 'Reserved for future standardization';
773
        if (mac_equals($mac, '01:80:C2:00:00:10')) $app = 'All LANs Bridge Management group address (deprecated)';
774
        if (mac_equals($mac, '01:80:C2:00:00:10')) $app = 'Bridge Management, EtherType is 0x0802';
775
        if (mac_equals($mac, '01:80:C2:00:00:11')) $app = 'Load Server generic address';
776
        if (mac_equals($mac, '01:80:C2:00:00:11')) $app = 'Load Server, EtherType is 0x0802';
777
        if (mac_equals($mac, '01:80:C2:00:00:12')) $app = 'Loadable Device generic address';
778
        if (mac_equals($mac, '01:80:C2:00:00:12')) $app = 'Loadable Device, EtherType is 0x0802';
779
        if (mac_equals($mac, '01:80:C2:00:00:13')) $app = 'Transmission of IEEE 1905.1 control packets';
780
        if (mac_equals($mac, '01:80:C2:00:00:14')) $app = 'All Level 1 Intermediate Systems address';
781
        if (mac_equals($mac, '01:80:C2:00:00:14')) $app = 'OSI Route level 1 (within area), EtherType is 0x0802';
782
        if (mac_equals($mac, '01:80:C2:00:00:15')) $app = 'All Level 2 Intermediate Systems address';
783
        if (mac_equals($mac, '01:80:C2:00:00:15')) $app = 'OSI Route level 2 (between area), EtherType is 0x0802';
784
        if (mac_equals($mac, '01:80:C2:00:00:16')) $app = 'All CONS End Systems address';
785
        if (mac_equals($mac, '01:80:C2:00:00:17')) $app = 'All CONS SNARES address';
786
        if (mac_equals($mac, '01:80:C2:00:00:18')) $app = 'Generic address for All Manager Stations';
787
        if (mac_equals($mac, '01:80:C2:00:00:19')) $app = 'Groupcast with retries (GCR) MAC group address';
788
        if (mac_between($mac, '01:80:C2:00:00:20', '01:80:C2:00:00:2F')) $app = 'Reserved for use by Multiple Registration Protocol (MRP) applications';
789
        if (mac_equals($mac, '01:80:C2:00:00:21')) $app = 'GARP VLAN Registration Protocol (also known as IEEE 802.1q GVRP), EtherType is 0x88f5';
790
        if (mac_between($mac, '01:80:C2:00:00:30', '01:80:C2:00:00:3F')) $app = 'Destination group MAC addresses for CCM and Linktrace messages';
791
        if (mac_between($mac, '01:80:C2:00:00:30', '01:80:C2:00:00:3F')) $app = 'Ethernet CFM Protocol IEEE 802.1ag, EtherType is 0x8902';
792
        if (mac_between($mac, '01:80:C2:00:00:50', '01:80:C2:00:00:FF')) $app = 'Unassigned standard group MAC address';
793
        if (mac_equals($mac, '01:80:C2:00:01:00')) $app = 'Ring Management Directed Beacon multicast address';
794
        if (mac_equals($mac, '01:80:C2:00:01:00')) $app = 'FDDI RMT Directed Beacon, EtherType is 0x0802';
795
        if (mac_between($mac, '01:80:C2:00:01:01', '01:80:C2:00:01:0F')) $app = 'Assigned to ISO/IEC JTC1/SC25 for future use';
796
        if (mac_equals($mac, '01:80:C2:00:01:10')) $app = 'Status Report Frame Status Report Protocol multicast address';
797
        if (mac_equals($mac, '01:80:C2:00:01:10')) $app = 'FDDI status report frame, EtherType is 0x0802';
798
        if (mac_between($mac, '01:80:C2:00:01:11', '01:80:C2:00:01:1F')) $app = 'Assigned to ISO/IEC JTC1/SC25 for future use';
799
        if (mac_equals($mac, '01:80:C2:00:01:20')) $app = 'All FDDI Concentrator MACs';
800
        if (mac_between($mac, '01:80:C2:00:01:21', '01:80:C2:00:01:2F')) $app = 'Assigned to ISO/IEC JTC1/SC25 for future use';
801
        if (mac_equals($mac, '01:80:C2:00:01:30')) $app = 'Synchronous Bandwidth Allocation address';
802
        if (mac_between($mac, '01:80:C2:00:01:31', '01:80:C2:00:01:FF')) $app = 'Assigned to ISO/IEC JTC1/SC25 for future use';
803
        if (mac_between($mac, '01:80:C2:00:02:00', '01:80:C2:00:02:FF')) $app = 'Assigned to ETSI for future use';
804
        if (mac_between($mac, '01:80:C2:00:03:00', '01:80:C2:FF-FF-FF')) $app = 'Unassigned standard group MAC address';
805
        if (mac_equals($mac, '09:00:4C:00:00:00')) $app = 'BICC 802.1 management, EtherType is 0x0802';
806
        if (mac_equals($mac, '09:00:4C:00:00:0C')) $app = 'BICC Remote bridge STA 802.1(D) Rev8, EtherType is 0x0802';
807
        if (mac_equals($mac, '09:00:4C:00:00:02')) $app = 'BICC 802.1 management, EtherType is 0x0802';
808
        if (mac_equals($mac, '09:00:4C:00:00:06')) $app = 'BICC Local bridge STA 802.1(D) Rev6, EtherType is 0x0802';
809
        if (mac_between($mac, '33:33:00:00:00:00', '33:33:FF:FF:FF:FF')) $app = 'IPv6 multicast, EtherType is 0x86DD';
810
 
811
        // === FAQ "How to recognise an ISO 9542 ES-IS protocol's MAC address application?" ===
812
        // https://standards.ieee.org/products-services/regauth/grpmac/public.html
813
        if (mac_equals($mac, '09:00:2B:00:00:04')) $app = 'All End System Network Entities address';
814
        if (mac_equals($mac, '09:00:2B:00:00:05')) $app = 'All Intermediate System Network Entities address';
815
 
816
        // === FAQ "How to recognise an IANA MAC address application?" ===
817
        // https://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml
818
        // http://www.iana.org/go/rfc7042
819
        // https://tools.ietf.org/html/rfc1060
820
        if (mac_between($mac, '00:00:5E:00-52:14', '00:00:5E:00:52:FF')) $app = 'Unassigned (small allocations)';
821
        if (mac_between($mac, '00:00:5E:00:00:00', '00:00:5E:00:00:FF')) $app = 'Reserved and require IESG Ratification for assignment';
822
        if (mac_between($mac, '00:00:5E:00:03:00', '00:00:5E:00:51:FF')) $app = 'Unassigned';
823
        if (mac_between($mac, '00:00:5E:00:52:00', '00:00:5E:00:52:FF')) $app = 'Is used for very small assignments. Currently, 3 out of these 256 values have been assigned.';
824
        if (mac_between($mac, '00:00:5E:00:52:00', '00:00:5E:00:52:00')) $app = 'PacketPWEthA';
825
        if (mac_between($mac, '00:00:5E:00:52:01', '00:00:5E:00:52:01')) $app = 'PacketPWEthB';
826
        if (mac_between($mac, '00:00:5E:00:52:02', '00:00:5E:00:52:12')) $app = 'Unassigned (small allocations)';
827
        if (mac_between($mac, '00:00:5E:00:53:00', '00:00:5E:00:53:FF')) $app = 'Assigned for use in documentation';
828
        if (mac_between($mac, '00:00:5E:00:54:00', '00:00:5E:90:00:FF')) $app = 'Unassigned';
829
        if (mac_between($mac, '00:00:5E:90:01:01', '00:00:5E:90:01:FF')) $app = 'Unassigned (small allocations requiring both unicast and multicast)';
16 daniel-mar 830
        if (mac_between($mac, '00:00:5E:EF:10:00:00:00', '00:00:5E:EF:10:00:00:FF')) $app = 'General documentation';
831
        if (mac_between($mac, '00:00:5E:FF:FE:00:53:00', '00:00:5E:FF:FE:00:53:FF')) $app = 'EUI-48 derived documentation';
15 daniel-mar 832
        if (mac_between($mac, '01:00:5E:00:00:00', '01:00:5E:7F:FF:FF')) $app = 'DoD Internet Multicast (EtherType is 0x0800)'; // TODO: IPv4-Multicast  (Dabei werden dann die unteren 23 Bit der IP-Multicast-Adresse direkt auf die untersten 23 Bit der MAC-Adresse abgebildet. Der IP-Multicast-Adresse 224.0.0.1 ist somit die Multicast-MAC-Adresse 01-00-5e-00-00-01 fest zugeordnet.)
833
        if (mac_between($mac, '01:00:5E:80:00:00', '01:00:5E:FF:FF:FF')) $app = 'DoD Internet';
834
        if (mac_equals($mac, '01:00:5E:90:00:02')) $app = 'AllL1MI-ISs';
835
        if (mac_equals($mac, '01:00:5E:90:00:03')) $app = 'AllL2MI-ISs';
836
        if (mac_between($mac, '01:00:5E:90:00:04', '01:00:5E:90:00:FF')) $app = 'Unassigned (small allocations)';
837
        if (mac_between($mac, '01:00:5E:90:01:01', '01:00:5E:90:01:FF')) $app = 'Unassigned (small allocations requiring both unicast and multicast)';
838
        if (mac_between($mac, '01:00:5E:90:02:00', '01:00:5E:90:0F:FF')) $app = 'Unassigned';
839
        if (mac_between($mac, '01:00:5E:90:02:00', '00:00:5E:FF:FF:FF')) $app = 'Unassigned';
840
        if (mac_between($mac, '01:00:5E:90:10:00', '01:00:5E:90:10:FF')) $app = 'Documentation';
841
        if (mac_between($mac, '01:00:5E:90:11:00', '01:00:5E:FF:FF:FF')) $app = 'Unassigned';
16 daniel-mar 842
        if (mac_between($mac, '01:00:5E:EF:10:00:00:00', '01:00:5E:EF:10:00:00:FF')) $app = 'General documentation';
843
        if (mac_between($mac, '02:00:5E:00:00:00:00:00', '02:00:5E:0F:FF:FF:FF:FF')) $app = 'Reserved';
844
        if (mac_between($mac, '02:00:5E:10:00:00:00:00', '02:00:5E:10:00:00:00:FF')) $app = 'Documentation';
845
        if (mac_between($mac, '02:00:5E:10:00:00:01:00', '02:00:5E:EF:FF:FF:FF:FF')) $app = 'Unassigned';
846
        if (mac_between($mac, '02:00:5E:F0:00:00:00:00', '02:00:5E:FD:FF:FF:FF:FF')) $app = 'Reserved';
847
        if (mac_between($mac, '02:00:5E:FE:00:00:00:00', '02:00:5E:FE:FF:FF:FF:FF')) $app = 'IPv4 Addr Holders';
848
        if (mac_between($mac, '02:00:5E:FF:00:00:00:00', '02:00:5E:FF:FD:FF:FF:FF')) $app = 'Reserved';
849
        if (mac_between($mac, '02:00:5E:FF:FE:00:00:00', '02:00:5E:FF:FE:FF:FF:FF')) $app = 'IANA EUI-48 Holders';
850
        if (mac_between($mac, '02:00:5E:FF:FF:00:00:00', '02:00:5E:FF:FF:FF:FF:FF')) $app = 'Reserved';
851
        if (mac_between($mac, '03:00:5E:00:00:00:00:00', '03:00:5E:0F:FF:FF:FF:FF')) $app = 'Reserved';
852
        if (mac_between($mac, '03:00:5E:10:00:00:00:00', '03:00:5E:10:00:00:00:FF')) $app = 'Documentation';
853
        if (mac_between($mac, '03:00:5E:10:00:00:01:00', '03:00:5E:EF:FF:FF:FF:FF')) $app = 'Unassigned';
854
        if (mac_between($mac, '03:00:5E:F0:00:00:00:00', '03:00:5E:FD:FF:FF:FF:FF')) $app = 'Reserved';
855
        if (mac_between($mac, '03:00:5E:FF:00:00:00:00', '03:00:5E:FF:FD:FF:FF:FF')) $app = 'Reserved';
856
        if (mac_between($mac, '03:00:5E:FF:FE:00:00:00', '03:00:5E:FF:FE:FF:FF:FF')) $app = 'IANA EUI-48 Holders';
857
        if (mac_between($mac, '03:00:5E:FF:FF:00:00:00', '03:00:5E:FF:FF:FF:FF:FF')) $app = 'Reserved';
15 daniel-mar 858
 
859
        // === FAQ "How to recognise a Cisco's MAC address application?" ===
860
        // https://www.cisco.com/c/en/us/support/docs/switches/catalyst-4500-series-switches/13414-103.html
861
        // https://tools.ietf.org/html/rfc1060
862
        // https://en.wikipedia.org/wiki/Multicast_address#cite_note-15
863
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
864
        if (mac_equals($mac, '01:00:0C:00:00:00')) $app = 'Inter Switch Link (ISL)';
865
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'CDP (Cisco Discovery Protocol), VTP (VLAN Trunking Protocol), EtherType is 0x0802';
866
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Port Aggregation Protocol (PAgP), SNAP HDLC Protocol Type is 0x0104';
867
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Unidirectional Link Detection (UDLD), SNAP HDLC Protocol Type is 0x0111';
868
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Dynamic Trunking (DTP), SNAP HDLC Protocol Type is 0x2004';
869
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'VLAN Trunking (VTP), SNAP HDLC Protocol Type is 0x2003';
870
        if (mac_equals($mac, '01:00:0C:CC:CC:CD')) $app = 'Cisco Shared Spanning Tree Protocol address, EtherType is 0x0802';
871
        if (mac_equals($mac, '01:00:0C:CC:CC:CD')) $app = 'Spanning Tree PVSTP+, SNAP HDLC Protocol Type is 0x010B';
872
        if (mac_equals($mac, '01:00:0C:CD:CD:CD')) $app = 'STP Uplink Fast, SNAP HDLC Protocol Type is 0x200A';
873
        if (mac_equals($mac, '01:00:0C:CD:CD:CE')) $app = 'VLAN Bridge, SNAP HDLC Protocol Type is 0x010C';
874
        if (mac_equals($mac, '01:00:0C:DD:DD:DD')) $app = 'CGMP (Cisco Group Management Protocol)';
875
 
876
        // === FAQ "How to recognise an ITU-T's MAC address application?" ===
877
        // https://www.itu.int/en/ITU-T/studygroups/2017-2020/15/Documents/IEEE-assigned_OUIs-30-06-2017.docx
878
        if (mac_between($mac, '01:19:A7:00:00:00', '01:19:A7:00:00:FF')) $app = 'R-APS per G.8032';
879
        if (mac_between($mac, '01:19:A7:52:76:90', '01:19:A7:52:76:9F')) $app = 'Multicast per G.9961';
880
 
881
        // === FAQ "How to recognise Digital Equipment Corporation's MAC address application?" ===
882
        if (mac_equals($mac, '09:00:2B:00:00:00')) $app = 'DEC MUMPS, EtherType is 0x6009';
883
        if (mac_equals($mac, '09:00:2B:00:00:0F')) $app = 'DEC Local Area Transport (LAT), EtherType is 0x6004';
884
        if (mac_equals($mac, '09:00:2B:00:00:01')) $app = 'DEC DSM/DDP, EtherType is 0x8039';
885
        if (mac_between($mac, '09:00:2B:00:00:10', '09:00:2B:00:00:1F')) $app = 'DEC Experimental';
886
        if (mac_equals($mac, '09:00:2B:00:00:02')) $app = 'DEC VAXELN, EtherType is 0x803B';
887
        if (mac_equals($mac, '09:00:2B:00:00:03')) $app = 'DEC Lanbridge Traffic Monitor (LTM), EtherType is 0x8038';
888
        if (mac_equals($mac, '09:00:2B:00:00:04')) $app = 'DEC MAP End System';
889
        if (mac_equals($mac, '09:00:2B:00:00:05')) $app = 'DEC MAP Intermediate System';
890
        if (mac_equals($mac, '09:00:2B:00:00:06')) $app = 'DEC CSMA/CD Encryption, EtherType is 0x803D';
891
        if (mac_equals($mac, '09:00:2B:00:00:07')) $app = 'DEC NetBios Emulator, EtherType is 0x8040';
892
        if (mac_equals($mac, '09:00:2B:01:00:00')) $app = 'DEC LanBridge, EtherType is 0x8038';
893
        if (mac_equals($mac, '09:00:2B:01:00:01')) $app = 'DEC LanBridge, EtherType is 0x8038';
894
        if (mac_equals($mac, '09:00:2B:02:00:00')) $app = 'DEC DNA Level 2 Routing';
895
        if (mac_equals($mac, '09:00:2B:02:01:00')) $app = 'DEC DNA Naming Service Advertisement, EtherType is 0x803C';
896
        if (mac_equals($mac, '09:00:2B:02:01:01')) $app = 'DEC DNA Naming Service Solicitation, EtherType is 0x803C';
897
        if (mac_equals($mac, '09:00:2B:02:01:02')) $app = 'DEC Distributed Time Service, EtherType is 0x803E';
898
        if (mac_equals($mac, '09:00:2B:02:01:09')) $app = 'DEC Availability Manager for Distributed Systems DECamds, EtherType is 0x8048';
899
        if (mac_between($mac, '09:00:2B:03:00:00', '09:00:2B:03:FF:FF')) $app = 'DEC default filtering by bridges';
900
        if (mac_equals($mac, '09:00:2B:04:00:00')) $app = 'DEC Local Area System Transport (LAST), EtherType is 0x8041';
901
        if (mac_equals($mac, '09:00:2B:23:00:00')) $app = 'DEC Argonaut Console, EtherType is 0x803A';
902
        if (mac_equals($mac, 'AB:00:00:01:00:00')) $app = 'DEC Maintenance Operation Protocol (MOP) Dump/Load Assistance, EtherType is 0x6001';
903
        if (mac_equals($mac, 'AB:00:00:02:00:00')) $app = 'DEC Maintenance Operation Protocol (MOP), EtherType is 0x6002';
904
        if (mac_equals($mac, 'AB:00:00:03:00:00')) $app = 'DECNET Phase IV end node, EtherType is 0x6003';
905
        if (mac_equals($mac, 'AB:00:00:04:00:00')) $app = 'DECNET Phase IV Router, EtherType is 0x6003';
906
        if (mac_between($mac, 'AB:00:00:05:00:00', 'AB:00:03:FF:FF:FF')) $app = 'Reserved DEC';
907
        if (mac_equals($mac, 'AB:00:03:00:00:00')) $app = 'DEC Local Area Transport (LAT) - old, EtherType is 0x6004';
908
        if (mac_between($mac, 'AB:00:04:00:00:00', 'AB:00:04:00:FF:FF')) $app = 'Reserved DEC customer private use';
16 daniel-mar 909
        if (mac_between($mac, 'AB:00:04:01:00:00', 'AB:00:04:01:FF:FF')) $app = 'DEC Local Area VAX Cluster groups System Communication Architecture (SCA), EtherType is 0x6007';
15 daniel-mar 910
 
21 daniel-mar 911
        // https://standards.ieee.org/products-programs/regauth/grpmac/public/
912
        // TODO: Check for duplicates between these and the ones at the top
913
        // IEEE Std 802.1D and IEEE Std 802.1Q Reserved Addresses
914
        if (mac_equals($mac, '01-80-C2-00-00-00')) $app = 'IEEE Std 802.1Q / Bridge Group address, Nearest Customer Bridge group address';
915
        if (mac_equals($mac, '01-80-C2-00-00-01')) $app = 'IEEE Std 802.1Q / IEEE MAC-specific Control Protocols group address';
916
        if (mac_equals($mac, '01-80-C2-00-00-02')) $app = 'IEEE Std 802.1Q / IEEE 802.3 Slow_Protocols_Multicast address';
917
        if (mac_equals($mac, '01-80-C2-00-00-03')) $app = 'IEEE Std 802.1Q / Nearest non-TPMR Bridge group address, IEEE Std 802.1X PAE address';
918
        if (mac_equals($mac, '01-80-C2-00-00-04')) $app = 'IEEE Std 802.1Q / IEEE MAC-specific Control Protocols group address';
919
        if (mac_equals($mac, '01-80-C2-00-00-05')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
920
        if (mac_equals($mac, '01-80-C2-00-00-06')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
921
        if (mac_equals($mac, '01-80-C2-00-00-07')) $app = 'IEEE Std 802.1Q / MEF Forum ELMI protocol group address';
922
        if (mac_equals($mac, '01-80-C2-00-00-08')) $app = 'IEEE Std 802.1Q / Provider Bridge group address';
923
        if (mac_equals($mac, '01-80-C2-00-00-09')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
924
        if (mac_equals($mac, '01-80-C2-00-00-0A')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
925
        if (mac_equals($mac, '01-80-C2-00-00-0B')) $app = 'IEEE Std 802.1Q / EDE-SS PEP Address';
926
        if (mac_equals($mac, '01-80-C2-00-00-0C')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
927
        if (mac_equals($mac, '01-80-C2-00-00-0D')) $app = 'IEEE Std 802.1Q / Provider Bridge MVRP address';
928
        if (mac_equals($mac, '01-80-C2-00-00-0E')) $app = 'IEEE Std 802.1Q / Individual LAN Scope group address, Nearest Bridge group address';
929
        if (mac_equals($mac, '01-80-C2-00-00-0F')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
930
        // Standard Group MAC Addresses
931
        if (mac_equals($mac, '01-80-C2-00-00-10')) $app = 'All LANs Bridge Management Group Address (deprecated)';
932
        if (mac_equals($mac, '01-80-C2-00-00-11')) $app = 'Load Server Generic Address';
933
        if (mac_equals($mac, '01-80-C2-00-00-12')) $app = 'Loadable Device Generic Address';
934
        if (mac_equals($mac, '01-80-C2-00-00-13')) $app = 'Transmission of IEEE 1905.1 control packets';
935
        if (mac_equals($mac, '01-80-C2-00-00-14')) $app = 'All Level 1 Intermediate Systems Address';
936
        if (mac_equals($mac, '01-80-C2-00-00-15')) $app = 'All Level 2 Intermediate Systems Address';
937
        if (mac_equals($mac, '01-80-C2-00-00-16')) $app = 'All CONS End Systems Address';
938
        if (mac_equals($mac, '01-80-C2-00-00-17')) $app = 'All CONS SNARES Address';
939
        if (mac_equals($mac, '01-80-C2-00-00-18')) $app = 'Generic Address for All Manager Stations';
940
        if (mac_equals($mac, '01-80-C2-00-00-19')) $app = 'Groupcast with retries (GCR) MAC Group Address';
941
        if (mac_equals($mac, '01-80-C2-00-00-1A')) $app = 'Generic Address for All Agent Stations';
942
        if (mac_equals($mac, '01-80-C2-00-00-1B')) $app = 'All Multicast Capable End Systems Address';
943
        if (mac_equals($mac, '01-80-C2-00-00-1C')) $app = 'All Multicast Announcements Address';
944
        if (mac_equals($mac, '01-80-C2-00-00-1D')) $app = 'All Multicast Capable Intermediate Systems Address';
945
        if (mac_equals($mac, '01-80-C2-00-00-1E')) $app = 'All DTR Concentrators MAC Group Address';
946
        if (mac_equals($mac, '01-80-C2-00-00-1F')) $app = 'EDE-CC PEP Address';
947
        if (mac_between($mac, '01-80-C2-00-00-20','01-80-C2-00-00-2F')) $app = 'Reserved for use by Multiple Registration Protocol (MRP) applications';
948
        if (mac_between($mac, '01-80-C2-00-00-30','01-80-C2-00-00-3F')) $app = 'Destination group MAC addresses for CCM and Linktrace messages';
949
        if (mac_between($mac, '01-80-C2-00-00-40','01-80-C2-00-00-4F')) $app = 'Group MAC addresses used by the TRILL protocols';
950
        if (mac_between($mac, '01-80-C2-00-00-50','01-80-C2-00-00-FF')) $app = 'unassigned';
951
        if (mac_equals($mac, '01-80-C2-00-01-00')) $app = 'Ring Management Directed Beacon Multicast Address';
952
        if (mac_between($mac, '01-80-C2-00-01-01','01-80-C2-00-01-0F')) $app = 'Assigned to ISO/IEC JTC1/SC25 for future use';
953
        if (mac_equals($mac, '01-80-C2-00-01-10')) $app = 'Status Report Frame Status Report Protocol Multicast Address';
954
        if (mac_between($mac, '01-80-C2-00-01-11','01-80-C2-00-01-1F')) $app = 'Assigned to ISO/IEC JTC1/SC25 for future use';
955
        if (mac_equals($mac, '01-80-C2-00-01-20')) $app = 'ISO/IEC 9314-2 All FDDI Concentrator MACs';
956
        if (mac_between($mac, '01-80-C2-00-01-21','01-80-C2-00-01-2F')) $app = 'Assigned to ISO/IEC JTC1/SC25 for future use';
957
        if (mac_equals($mac, '01-80-C2-00-01-30')) $app = 'ISO/IEC 9314-6 Synchronous Bandwidth Allocation Address';
958
        if (mac_between($mac, '01-80-C2-00-01-31','01-80-C2-00-01-FF')) $app = 'Assigned to ISO/IEC JTC1/SC25 for future use';
959
        if (mac_between($mac, '01-80-C2-00-02-00','01-80-C2-00-02-FF')) $app = 'Assigned to ETSI for future use';
960
        if (mac_between($mac, '01-80-C2-00-03-00', '01-80-C2-FF-FF-FF')) $app = 'unassigned';
961
        if (mac_equals($mac, '09-00-2B-00-00-04')) $app = 'ISO 9542 All End System Network Entities Address';
962
        if (mac_equals($mac, '09-00-2B-00-00-05')) $app = 'ISO 9542 All Intermediate System Network Entities Address';
963
        // Group MAC Addresses Used in ISO 9542 ES-IS Protocol
964
        if (mac_equals($mac, '09-00-2B-00-00-04')) $app = 'ISO 9542 All End System Network Entities Address';
965
        if (mac_equals($mac, '09-00-2B-00-00-05')) $app = 'ISO 9542 All Intermediate System Network Entities Address';
966
        // Locally Administered Group MAC Addresses Used by IEEE Std 802.5 (IEEE Std 802.5 Functional Addresses)
967
        if (mac_equals($mac, '03-00-00-00-00-08')) $app = 'Configuration Report Server (CRS) MAC Group Address';
968
        if (mac_equals($mac, '03-00-00-00-00-10')) $app = 'Ring Error Monitor (REM) MAC Group Address';
969
        if (mac_equals($mac, '03-00-00-00-00-40')) $app = 'Ring Parameter Server (RPS) MAC Group Address';
970
        if (mac_equals($mac, '03-00-00-00-01-00')) $app = 'All Intermediate System Network Entities Address';
971
        if (mac_equals($mac, '03-00-00-00-02-00')) $app = 'All End System Network Entities Address, and Lobe Media Test (LMT) MAC Group Address';
972
        if (mac_equals($mac, '03-00-00-00-04-00')) $app = 'Generic Address for all Manager Stations';
973
        if (mac_equals($mac, '03-00-00-00-08-00')) $app = 'All CONs SNARES Address';
974
        if (mac_equals($mac, '03-00-00-00-10-00')) $app = 'All CONs End System Address';
975
        if (mac_equals($mac, '03-00-00-00-20-00')) $app = 'Loadable Device Generic Address';
976
        if (mac_equals($mac, '03-00-00-00-40-00')) $app = 'Load Server Generic Address';
977
        if (mac_equals($mac, '03-00-00-40-00-00')) $app = 'Generic Address for all Agent Stations';
978
 
15 daniel-mar 979
        if ($app) {
980
                echo sprintf("%-32s %s\n", "Special use:", $app);
981
        }
982
 
2 daniel-mar 983
}
15 daniel-mar 984
 
985
/**
986
 * @param string $mac1
987
 * @param string $mac2
988
 * @return bool
989
 */
990
function mac_equals(string $mac1, string $mac2): bool {
16 daniel-mar 991
        $mac1test = eui64_to_eui48($mac1);
992
        if ($mac1test === false) return false;
993
        $mac2test = eui64_to_eui48($mac2);
994
        if ($mac2test === false) return false;
995
 
996
        if (eui_bits($mac1test) != eui_bits($mac2test)) {
997
                $mac1test = eui48_to_eui64($mac1);
998
                $mac2test = eui48_to_eui64($mac2);
999
        }
1000
 
1001
        return mac_canonize($mac1test) == mac_canonize($mac2test);
15 daniel-mar 1002
}
1003
 
1004
/**
1005
 * @param string $mac
1006
 * @param string $low
1007
 * @param string $high
1008
 * @return bool
1009
 */
1010
function mac_between(string $mac, string $low, string $high): bool {
16 daniel-mar 1011
        $mactest = eui64_to_eui48($mac);
1012
        if ($mactest === false) return false;
1013
        $lowtest = eui64_to_eui48($low);
1014
        if ($lowtest === false) return false;
1015
        $hightest = eui64_to_eui48($high);
1016
        if ($hightest === false) return false;
15 daniel-mar 1017
 
16 daniel-mar 1018
        if ((eui_bits($mactest) != eui_bits($lowtest)) || (eui_bits($lowtest) != eui_bits($hightest))) {
1019
                $mactest = eui48_to_eui64($mac);
18 daniel-mar 1020
                if ($mactest === false) return false; // e.g. trying ELI-48 to ELI-64
16 daniel-mar 1021
                $lowtest = eui48_to_eui64($low);
18 daniel-mar 1022
                if ($lowtest === false) return false; // e.g. trying ELI-48 to ELI-64
16 daniel-mar 1023
                $hightest = eui48_to_eui64($high);
18 daniel-mar 1024
                if ($hightest === false) return false; // e.g. trying ELI-48 to ELI-64
16 daniel-mar 1025
        }
15 daniel-mar 1026
 
16 daniel-mar 1027
        $mactest = strtoupper(preg_replace('@[^0-9A-F]@', '', $mactest));
1028
        $lowtest = strtoupper(preg_replace('@[^0-9A-F]@', '', $lowtest));
1029
        $hightest = strtoupper(preg_replace('@[^0-9A-F]@', '', $hightest));
15 daniel-mar 1030
 
16 daniel-mar 1031
        $mactest = gmp_init($mactest, 16);
1032
        $lowtest = gmp_init($lowtest, 16);
1033
        $hightest = gmp_init($hightest, 16);
15 daniel-mar 1034
 
16 daniel-mar 1035
        return (gmp_cmp($mactest, $lowtest) >= 0) && (gmp_cmp($mactest, $hightest) <= 0);
17 daniel-mar 1036
}