Subversion Repositories uuid_mac_utils

Rev

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