Subversion Repositories uuid_mac_utils

Rev

Rev 20 | Rev 22 | 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
21 daniel-mar 6
 * Version 2023-05-04
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
 
15 daniel-mar 115
                $out = sprintf("%-32s 0x%s\n", "IEEE $oui_name part:", substr($mac, 0, 12-$ra_len));
116
                $out .= sprintf("%-32s 0x%s\n", "NIC specific part:", substr($mac, 12-$ra_len));
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)
219
        $tmp = inet_pton($ipv6);
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)
270
         * 1    0001
271
         * 2    0010    AAI
272
         * 3    0011
273
         * 4    0100    EUI (OUI)
274
         * 5    0101
275
         * 6    0110    Reserved
276
         * 7    0111
277
         * 8    1000    EUI (OUI)
278
         * 9    1001
279
         * A    1010    ELI (CID)
280
         * B    1011
281
         * C    1100    EUI (OUI)
282
         * D    1101
283
         * E    1110    SAI
284
         * F    1111
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) {
296
                if ($mac[1] == '2') {
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)';
305
                } else if ($mac[1] == '6') {
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);
315
                } else if ($mac[1] == 'A') {
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)';
323
                } else if ($mac[1] == 'E') {
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)';
340
                } else if ((hexdec($mac[1])&1) == 1) {
341
                        $type = 'Multicast MAC-'.eui_bits($mac);
342
                } else if (($mac[1] == '0') || ($mac[1] == '4') || ($mac[1] == '8') || ($mac[1] == 'C')) {
343
                        /*
344
                         * Extended Unique Identifier
345
                         * Based on an OUI-24, OUI-28, or OUI-36
346
                         */
18 daniel-mar 347
                        if (eui_bits($mac) == 48) {
20 daniel-mar 348
                                // The name "MAC-48" has been deprecated by IEEE
349
                                //$type = 'MAC-48 (network hardware) or EUI-48 (other devices and software)';
350
                                $type = 'EUI-48 (Extended Unique Identifier)';
18 daniel-mar 351
                        } else if (eui_bits($mac) == 64) {
20 daniel-mar 352
                                if (substr($mac, 6, 4) == 'FFFE') {
353
                                        if ((hexdec($mac[1]) & 2) == 2) {
354
                                                $type = 'EUI-64 (Extended Unique Identifier, MAC/EUI-48 to Modified EUI-64 Encapsulation)';
18 daniel-mar 355
                                        } else {
20 daniel-mar 356
                                                $type = 'EUI-64 (Extended Unique Identifier, EUI-48 to EUI-64 Encapsulation)';
18 daniel-mar 357
                                        }
20 daniel-mar 358
                                } else if (substr($mac, 6, 4) == 'FFFF') {
359
                                        $type = 'EUI-64 (Extended Unique Identifier, MAC-48 to EUI-64 Encapsulation)';
17 daniel-mar 360
                                } else {
20 daniel-mar 361
                                        $type = 'EUI-64 (Extended Unique Identifier)';
17 daniel-mar 362
                                }
363
                        } else {
18 daniel-mar 364
                                assert(false); /** @phpstan-ignore-line */
17 daniel-mar 365
                        }
366
                }
16 daniel-mar 367
        }
20 daniel-mar 368
        return $type;
369
}
370
 
371
/**
372
 * Prints information about an IPv6-Link-Local address, MAC, EUI, ELI, AAI, or SAI.
373
 * @param string $mac IPv6-Link-Local address, MAC, EUI, ELI, AAI, or SAI
374
 * @return void
375
 * @throws Exception
376
 */
377
function decode_mac(string $mac) {
21 daniel-mar 378
 
379
        // TODO: Should we decode Multicast MAC to its IP (see https://ipcisco.com/lesson/multicast-mac-addresses/)?
380
        // TODO: Is an ELI with M=1 a Multicast-ELI, or isn't it an ELI anymore? Same question for SAI and AAI
381
 
20 daniel-mar 382
        echo sprintf("%-32s %s\n", "Input:", $mac);
383
 
384
        // Format MAC for machine readability
385
        $mac = mac_canonize($mac, '');
386
 
387
        $type = mac_type($mac);
16 daniel-mar 388
        echo sprintf("%-32s %s\n", "Type:", $type);
15 daniel-mar 389
 
16 daniel-mar 390
        echo "\n";
391
 
392
        // Show various representations
18 daniel-mar 393
        if ($mac[1] == 'A') {
20 daniel-mar 394
                // Note: There does not seem to exist an algorithm for encapsulating/converting ELI-48 <=> ELI-64
18 daniel-mar 395
                echo sprintf("%-32s %s\n", "ELI-".eui_bits($mac).":", mac_canonize($mac));
19 daniel-mar 396
                $mac48 = eui64_to_eui48($mac);
397
                echo sprintf("%-32s %s\n", "MAC-48 (Local):", (eui_bits($mac48) != 48) ? 'Not available' : $mac48);
20 daniel-mar 398
        } else if (($mac[1] == '0') || ($mac[1] == '4') || ($mac[1] == '8') || ($mac[1] == 'C')) {
18 daniel-mar 399
                $eui48 = eui64_to_eui48($mac);
19 daniel-mar 400
                echo sprintf("%-32s %s\n", "EUI-48 or MAC-48:", (eui_bits($eui48) != 48) ? 'Not available' : $eui48);
18 daniel-mar 401
                if (eui_bits($mac) == 48) {
402
                        $eui64 = mac48_to_eui64($mac);
403
                        echo sprintf("%-32s %s\n", "EUI-64:", ((eui_bits($eui64) != 64) ? 'Not available' : $eui64).' (MAC-48 to EUI-64 Encapsulation)');
404
                        $eui64 = eui48_to_eui64($mac);
405
                        echo sprintf("%-32s %s\n", "", ((eui_bits($eui64) != 64) ? 'Not available' : $eui64).' (EUI-48 to EUI-64 Encapsulation)');
406
                        $eui64 = maceui48_to_modeui64($mac);
407
                        echo sprintf("%-32s %s\n", "", ((eui_bits($eui64) != 64) ? 'Not available' : $eui64).' (MAC/EUI-48 to Modified EUI-64 Encapsulation)');
408
                        $ipv6 = maceui_to_ipv6linklocal($mac);
19 daniel-mar 409
                        echo sprintf("%-32s %s\n", "IPv6-Link-Local address:", $ipv6);
18 daniel-mar 410
                } else {
411
                        $eui64 = mac_canonize($mac);
412
                        echo sprintf("%-32s %s\n", "EUI-64:", $eui64);
413
                }
17 daniel-mar 414
        }
2 daniel-mar 415
 
416
        // Vergabestelle
417
        $ul = hexdec($mac[1]) & 2; // Bit #LSB+1 of Byte 1
418
        $ul_ = ($ul == 0) ? '[0] Universally Administered Address (UAA)' : '[1] Locally Administered Address (LAA)';
15 daniel-mar 419
        echo sprintf("%-32s %s\n", "Administration type (U/L flag):", $ul_);
2 daniel-mar 420
 
16 daniel-mar 421
        // Empfaengergruppe
422
        $ig = hexdec($mac[1]) & 1; // Bit #LSB+0 of Byte 1
18 daniel-mar 423
        $ig_ = ($ig == 0) ? '[0] Unicast (Individual)' : '[1] Multicast (Group)';
16 daniel-mar 424
        echo sprintf("%-32s %s\n", "Transmission type (I/G flag):", $ig_);
425
 
2 daniel-mar 426
        // Query IEEE registries
17 daniel-mar 427
        if (count(glob(IEEE_MAC_REGISTRY.DIRECTORY_SEPARATOR.'*.txt')) > 0) {
18 daniel-mar 428
                if ($mac[1] == 'A') {
429
                        // Query the CID registry
430
                        if (
431
                                ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'cid.txt', 'CID', $mac))
432
                        ) {
433
                                echo $x;
434
                        }
435
                } else {
436
                        // Query the OUI registries
437
                        // TODO: Should we try to convert Unicast<=>Multicast if one of them can't be found?
438
                        if (
439
                                # 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]
440
                                # 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.
441
                                ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'iab.txt', 'IAB', $mac)) ||
442
                                ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'oui36.txt', 'OUI-36 (MA-S)', $mac)) ||
443
                                ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'mam.txt', 'OUI-28 (MA-M)', $mac)) ||
444
                                ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'oui.txt', 'OUI-24 (MA-L)', $mac))
445
                        ) {
446
                                echo $x;
447
                        }
15 daniel-mar 448
                }
2 daniel-mar 449
        }
450
 
15 daniel-mar 451
        $vm = '';
452
        // === FAQ "Detection rules which don't have their dedicated page yet" ===
453
        // https://wiki.xenproject.org/wiki/Xen_Networking
454
        // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
455
        // https://www.techrepublic.com/blog/data-center/mac-address-scorecard-for-common-virtual-machine-platforms
456
        if (mac_between($mac, '00:16:3E:00:00:00', '00:16:3E:FF:FF:FF')) $vm = "Red Hat Xen, XenSource, Novell Xen";
457
        // http://techgenix.com/mac-address-pool-duplication-hyper-v/
458
        // https://docs.microsoft.com/en-us/system-center/vmm/network-mac?view=sc-vmm-1807
459
        // https://blogs.technet.microsoft.com/gbanin/2014/08/27/how-to-solve-mac-address-conflict-on-hyper-v/
460
        if (mac_between($mac, '00:1D:D8:B7:1C:00', '00:1D:D8:F4:1F:FF')) $vm = "Microsoft SCVMM (System Center Virtual Machine Manager)";
461
        // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
462
        // https://www.techrepublic.com/blog/data-center/mac-address-scorecard-for-common-virtual-machine-platforms/
463
        // https://blogs.technet.microsoft.com/medv/2011/01/24/how-to-manage-vm-mac-addresses-with-the-globalimagedata-xml-file-in-med-v-v1/
464
        if (mac_between($mac, '00:03:FF:00:00:00', '00:03:FF:FF:FF:FF')) $vm = "Microsoft Virtual PC / Virtual Server";
465
        // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
466
        if (mac_between($mac, '00:18:51:00:00:00', '00:18:51:FF:FF:FF')) $vm = "SWsoft";
467
        // https://macaddress.io/statistics/company/17619
468
        if (mac_between($mac, '58:9C:FC:00:00:00', '58:9C:FC:FF:FF:FF')) $vm = "bhyve by FreebsdF";
469
        // https://macaddress.io/statistics/company/17388
470
        if (mac_between($mac, '50:6B:8D:00:00:00', '50:6B:8D:FF:FF:FF')) $vm = "Nutanix AHV";
471
        // https://www.centos.org/forums/viewtopic.php?t=26739
472
        if (mac_between($mac, '54:52:00:00:00:00', '54:52:FF:FF:FF:FF')) $vm = "KVM (proxmox)";
473
        // Self tested (alldatafeeds.com)
474
        if (mac_between($mac, '96:00:00:00:00:00', '96:00:FF:FF:FF:FF')) $vm = "Hetzner vServer (based on KVM and libvirt)";
475
        // === FAQ "How to recognise a VMware's virtual machine by its MAC address?" ===
476
        if (mac_between($mac, '00:50:56:00:00:00', '00:50:56:FF:FF:FF')) $vm = "VMware vSphere, VMware Workstation, VMware ESX Server";
477
        if (mac_between($mac, '00:50:56:80:00:00', '00:50:56:BF:FF:FF')) $vm = "VMware vSphere managed by vCenter Server";
478
        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";
479
        if (mac_between($mac, '00:05:69:00:00:00', '00:05:69:FF:FF:FF')) $vm = "VMware ESX, VMware GSX Server";
480
        if (mac_between($mac, '00:1C:14:00:00:00', '00:1C:14:FF:FF:FF')) $vm = "VMWare";
481
        // === FAQ "machine by its MAC address?" ===
482
        if (mac_between($mac, '00:1C:42:00:00:00', '00:1C:42:FF:FF:FF')) $vm = "Parallels Virtual Machine";
483
        // === FAQ "How to recognise a Docker container by its MAC address?" ===
484
        if (mac_between($mac, '02:42:00:00:00:00', '02:42:FF:FF:FF:FF')) $vm = "Docker container";
485
        // === FAQ =How to recognise a Microsoft Hyper-V's virtual machine by its MAC address?" ===
486
        if (mac_between($mac, '00:15:5D:00:00:00', '00:15:5D:FF:FF:FF')) $vm = "Microsoft Hyper-V";
487
        // === FAQ "How to recognise an Oracle Virtual machine by its MAC address?" ===
488
        if (mac_between($mac, '08:00:27:00:00:00', '08:00:27:FF:FF:FF')) $vm = "Oracle VirtualBox 5.2"; // Pcs Systemtechnik GmbH
489
        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)
490
        if (mac_between($mac, '00:21:F6:00:00:00', '00:21:F6:FF:FF:FF')) $vm = "Oracle VirtualBox 3.3";
491
        if (mac_between($mac, '00:14:4F:00:00:00', '00:14:4F:FF:FF:FF')) $vm = "Oracle VM Server for SPARC";
492
        if (mac_between($mac, '00:0F:4B:00:00:00', '00:0F:4B:FF:FF:FF')) $vm = "Oracle Virtual Iron 4";
2 daniel-mar 493
 
15 daniel-mar 494
        if ($vm) {
495
                echo sprintf("%-32s %s\n", "Special use:", "Virtual machine $vm");
496
        }
2 daniel-mar 497
 
15 daniel-mar 498
        $app = '';
499
 
500
        // === FAQ "Other MAC address applications"
501
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
502
        // https://tools.ietf.org/html/rfc1060
503
        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';
504
        if (mac_equals($mac, '01:00:1D:00:00:00')) $app = 'Cabletron PC-OV PC discover (on demand), EtherType is 0x0802';
505
        if (mac_equals($mac, '01:00:1D:42:00:00')) $app = 'Cabletron PC-OV Bridge discover (on demand), EtherType is 0x0802';
506
        if (mac_equals($mac, '01:00:1D:52:00:00')) $app = 'Cabletron PC-OV MMAC discover (on demand), EtherType is 0x0802';
507
        if (mac_between($mac, '01:00:3C:00:00:00' , '01:00:3C:FF:FF:FF')) $app = 'Auspex Systems (Serverguard)';
508
        if (mac_equals($mac, '01:00:10:00:00:20')) $app = 'Hughes Lan Systems Terminal Server S/W download, EtherType is 0x0802';
509
        if (mac_equals($mac, '01:00:10:FF:FF:20')) $app = 'Hughes Lan Systems Terminal Server S/W request, EtherType is 0x0802';
510
        if (mac_equals($mac, '01:00:81:00:00:00')) $app = 'Synoptics Network Management';
511
        if (mac_equals($mac, '01:00:81:00:00:02')) $app = 'Synoptics Network Management';
512
        if (mac_equals($mac, '01:00:81:00:01:00')) $app = 'Bay Networks (Synoptics) autodiscovery, EtherType is 0x0802 SNAP type is 0x01A2';
513
        if (mac_equals($mac, '01:00:81:00:01:01')) $app = 'Bay Networks (Synoptics) autodiscovery, EtherType is 0x0802 SNAP type is 0x01A1';
514
        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';
515
        if (mac_equals($mac, '01:80:24:00:00:00')) $app = 'Kalpana Etherswitch every 60 seconds, EtherType is 0x0802';
516
        if (mac_equals($mac, '01:DD:00:FF:FF:FF')) $app = 'Ungermann-Bass boot-me requests, EtherType is 0x7002';
517
        if (mac_equals($mac, '01:DD:01:00:00:00')) $app = 'Ungermann-Bass Spanning Tree, EtherType is 0x7005';
518
        if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'OS/2 1.3 EE + Communications Manager, EtherType is 0x80D5';
519
        if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'OS/2 1.3 EE + Communications Manager, EtherType is 0x80D5';
520
        if (mac_equals($mac, '03:00:00:00:01:00')) $app = 'OSI All-IS Multicast, EtherType is 0x0802';
521
        if (mac_equals($mac, '03:00:00:00:02:00')) $app = 'OSI All-ES Multicast, EtherType is 0x0802';
522
        if (mac_equals($mac, '03:00:00:80:00:00')) $app = 'Discovery Client, EtherType is 0x0802';
523
        if (mac_equals($mac, '03:00:FF:FF:FF:FF')) $app = 'All Stations address, EtherType is 0x0802';
524
        if (mac_between($mac, '09:00:0D:00:00:00', '09:00:0D:FF:FF:FF')) $app = 'ICL Oslan Multicast, EtherType is 0x0802';
525
        if (mac_equals($mac, '09:00:0D:02:00:00')) $app = 'ICL Oslan Service discover only on boot';
526
        if (mac_equals($mac, '09:00:0D:02:0A:3C')) $app = 'ICL Oslan Service discover only on boot';
527
        if (mac_equals($mac, '09:00:0D:02:0A:38')) $app = 'ICL Oslan Service discover only on boot';
528
        if (mac_equals($mac, '09:00:0D:02:0A:39')) $app = 'ICL Oslan Service discover only on boot';
529
        if (mac_equals($mac, '09:00:0D:02:FF:FF')) $app = 'ICL Oslan Service discover only on boot';
530
        if (mac_equals($mac, '09:00:0D:09:00:00')) $app = 'ICL Oslan Service discover as required';
531
        if (mac_equals($mac, '09:00:1E:00:00:00')) $app = 'Apollo DOMAIN, EtherType is 0x8019';
532
        if (mac_equals($mac, '09:00:02:04:00:01')) $app = 'Vitalink printer messages, EtherType is 0x8080';
533
        if (mac_equals($mac, '09:00:02:04:00:02')) $app = 'Vitalink bridge management, EtherType is 0x8080';
534
        if (mac_equals($mac, '09:00:4C:00:00:0F')) $app = 'BICC Remote bridge adaptive routing (e.g. to Retix), EtherType is 0x0802';
535
        if (mac_equals($mac, '09:00:4E:00:00:02')) $app = 'Novell IPX, EtherType is 0x8137';
536
        if (mac_equals($mac, '09:00:6A:00:01:00')) $app = 'TOP NetBIOS';
537
        if (mac_equals($mac, '09:00:7C:01:00:01')) $app = 'Vitalink DLS Multicast';
538
        if (mac_equals($mac, '09:00:7C:01:00:03')) $app = 'Vitalink DLS Inlink';
539
        if (mac_equals($mac, '09:00:7C:01:00:04')) $app = 'Vitalink DLS and non DLS Multicast';
540
        if (mac_equals($mac, '09:00:7C:02:00:05')) $app = 'Vitalink diagnostics, EtherType is 0x8080';
541
        if (mac_equals($mac, '09:00:7C:05:00:01')) $app = 'Vitalink gateway, EtherType is 0x8080';
542
        if (mac_equals($mac, '09:00:7C:05:00:02')) $app = 'Vitalink Network Validation Message';
543
        if (mac_equals($mac, '09:00:09:00:00:01')) $app = 'HP Probe, EtherType is 0x8005 or 0x0802';
544
        if (mac_equals($mac, '09:00:09:00:00:04')) $app = 'HP DTC, EtherType is 0x8005';
545
        if (mac_equals($mac, '09:00:26:01:00:01')) $app = 'Vitalink TransLAN bridge management, EtherType is 0x8038';
546
        if (mac_equals($mac, '09:00:39:00:70:00')) $app = 'Spider Systems Bridge';
547
        if (mac_between($mac, '09:00:56:00:00:00', '09:00:56:FE:FF:FF')) $app = 'Stanford reserved';
548
        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';
549
        if (mac_equals($mac, '09:00:77:00:00:00')) $app = 'Retix Bridge Local Management System, EtherType is 0x0802';
550
        if (mac_equals($mac, '09:00:77:00:00:01')) $app = 'Retix spanning tree bridges, EtherType is 0x0802';
551
        if (mac_equals($mac, '09:00:77:00:00:02')) $app = 'Retix Bridge Adaptive routing, EtherType is 0x0802';
552
        if (mac_equals($mac, '09:00:87:80:FF:FF')) $app = 'Xyplex Terminal Servers, EtherType is 0x0889';
553
        if (mac_equals($mac, '09:00:87:90:FF:FF')) $app = 'Xyplex Terminal Servers, EtherType is 0x0889';
554
        if (mac_between($mac, '44:38:39:FF:00:00', '44:38:39:FF:FF:FF')) $app = 'Multi-Chassis Link Aggregation (Cumulus Linux)';
555
        if (mac_equals($mac, 'FF:FF:00:40:00:01')) $app = 'LANtastic, EtherType is 0x81D6';
556
        if (mac_equals($mac, 'FF:FF:00:60:00:04')) $app = 'LANtastic, EtherType is 0x81D6';
557
        if (mac_equals($mac, 'FF:FF:01:E0:00:04')) $app = 'LANtastic';
558
 
559
        // === FAQ "The "CF" series MAC addresses" ===
560
        // https://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml
561
        // https://tools.ietf.org/html/rfc2153
562
        // https://tools.ietf.org/html/rfc7042#section-2.3.2
563
        if (mac_between($mac, 'CF:00:00:00:00:00', 'CF:00:00:FF:FF:FF')) $app = 'Reserved';
564
        if (mac_equals($mac, 'CF:00:00:00:00:00')) $app = 'Used for Ethernet loopback tests';
565
 
566
        // === FAQ "How to recognise a Broadcast MAC address application?" ===
19 daniel-mar 567
        // According to https://standards.ieee.org/wp-content/uploads/import/documents/tutorials/eui.pdf FFFFFFFFFFFF can be used as NULL EUI
568
        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 569
 
570
        // === FAQ "How to recognise a Virtual Router ID by MAC address?" ===
571
        // https://tools.ietf.org/html/rfc7042#section-5.1
572
        // https://tools.ietf.org/html/rfc5798
573
        if (mac_between($mac, '00:00:5E:00:01:00', '00:00:5E:00:01:FF')) $app = 'IPv4 Virtual Router Redundancy Protocol  (VRRP)';
574
        if (mac_between($mac, '00:00:5E:00:02:00', '00:00:5E:00:02:FF')) $app = 'IPv6 Virtual Router Redundancy Protocol';
575
 
576
        // === FAQ "How to recognise an IP frame by MAC address?" ===
577
        // https://tools.ietf.org/html/rfc1060
578
        // https://en.wikipedia.org/wiki/Multicast_address#cite_note-15
579
        // https://tools.ietf.org/html/rfc2464
580
        // https://www.iana.org/go/rfc1112
581
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
582
        if (mac_between($mac, '01:00:5E:00:00:00', '01:00:5E:7F:FF:FF')) $app = 'IPv4 Multicast (EtherType is 0x0800)';
583
        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.
584
        if (mac_between($mac, '00:00:5E:00:52:13', '00:00:5E:00:52:13')) $app = 'Proxy Mobile IPv6';
16 daniel-mar 585
        if (mac_between($mac, '00:00:5E:FE:C0:00:02:00', '00:00:5E:FE:C0:00:02:FF')) $app = 'IPv4 derived documentation';
586
        if (mac_between($mac, '00:00:5E:FE:C6:33:64:00', '00:00:5E:FE:C6:33:64:FF')) $app = 'IPv4 derived documentation';
587
        if (mac_between($mac, '00:00:5E:FE:CB:00:71:00', '00:00:5E:FE:CB:00:71:FF')) $app = 'IPv4 derived documentation';
588
        if (mac_equals($mac, '00:00:5E:FE:EA:C0:00:02')) $app = 'IPv4 multicast derived documentation';
589
        if (mac_equals($mac, '00:00:5E:FE:EA:C6:33:64')) $app = 'IPv4 multicast derived documentation';
590
        if (mac_equals($mac, '00:00:5E:FE:EA:CB:00:71')) $app = 'IPv4 multicast derived documentation';
591
        if (mac_between($mac, '01:00:5E:FE:C0:00:02:00', '01:00:5E:FE:C0:00:02:FF')) $app = 'IPv4 derived documentation';
592
        if (mac_between($mac, '01:00:5E:FE:C6:33:64:00', '01:00:5E:FE:C6:33:64:FF')) $app = 'IPv4 derived documentation';
593
        if (mac_between($mac, '01:00:5E:FE:CB:00:71:00', '01:00:5E:FE:CB:00:71:FF')) $app = 'IPv4 derived documentation';
594
        if (mac_equals($mac, '01:00:5E:FE:EA:C0:00:02')) $app = 'IPv4 multicast derived documentation';
595
        if (mac_equals($mac, '01:00:5E:FE:EA:C6:33:64')) $app = 'IPv4 multicast derived documentation';
596
        if (mac_equals($mac, '01:00:5E:FE:EA:CB:00:71')) $app = 'IPv4 multicast derived documentation';
15 daniel-mar 597
        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 598
        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 599
        if (mac_equals($mac, '03:00:00:20:00:00')) $app = 'IP multicast address';
600
        if (mac_equals($mac, 'C0:00:00:04:00:00')) $app = 'IP multicast address';
16 daniel-mar 601
        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 602
 
603
        // === FAQ "How to recognise a MPLS multicast frame by MAC address?" ===
604
        // http://www.iana.org/go/rfc5332
605
        // http://www.iana.org/go/rfc7213
606
        if (mac_between($mac, '01:00:5E:80:00:00', '01:00:5E:8F:FF:FF')) $app = 'MPLS multicast (EtherType is 0x8847 or 0x8848)';
607
        if (mac_equals($mac, '01:00:5E:90:00:00')) $app = 'MPLS-TP p2p';
608
 
609
        // === FAQ "How to recognise a Bidirectional Forwarding Detection (BFD) on Link Aggregation Group (LAG) interfaces by MAC address?" ===
610
        // http://www.iana.org/go/rfc7130
611
        if (mac_equals($mac, '01:00:5E:90:00:01')) $app = 'Bidirectional Forwarding Detection (BFD) on Link Aggregation Group (LAG) interfaces';
612
 
613
        // === FAQ "How to recognise Token Ring specific functions by MAC address?" ===
614
        // https://tools.ietf.org/html/rfc1060
615
        // https://tools.ietf.org/html/rfc1469
616
        // https://standards.ieee.org/products-services/regauth/grpmac/public.html
617
        // https://tools.ietf.org/html/rfc2470
618
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
619
        if (mac_equals($mac, '03:00:00:00:00:01')) $app = 'NetBIOS (Token Ring)';
620
        if (mac_equals($mac, '03:00:00:00:00:02')) $app = 'Locate - Directory Server (Token Ring)';
621
        if (mac_equals($mac, '03:00:00:00:00:04')) $app = 'Synchronous Bandwidth Manager (Token Ring)';
622
        if (mac_equals($mac, '03:00:00:00:00:08')) $app = 'Configuration Report Server (Token Ring)';
623
        if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'Ring Error Monitor (Token Ring)';
624
        if (mac_equals($mac, '03:00:00:00:00:20')) $app = 'Network Server Heartbeat (Token Ring)';
625
        if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'Ring Parameter Monitor (Token Ring)';
626
        if (mac_equals($mac, '03:00:00:00:00:80')) $app = 'Active Monitor (Token Ring)';
627
        if (mac_equals($mac, '03:00:00:00:04:00')) $app = 'LAN Manager (Token Ring)';
628
        if (mac_equals($mac, '03:00:00:00:08:00')) $app = 'Ring Wiring Concentrator (Token Ring)';
629
        if (mac_equals($mac, '03:00:00:00:10:00')) $app = 'LAN Gateway (Token Ring)';
630
        if (mac_equals($mac, '03:00:00:00:20:00')) $app = 'Ring Authorization Server (Token Ring)';
631
        if (mac_equals($mac, '03:00:00:00:40:00')) $app = 'IMPL Server (Token Ring)';
632
        if (mac_equals($mac, '03:00:00:00:80:00')) $app = 'Bridge (Token Ring)';
633
        if (mac_equals($mac, '03:00:00:20:00:00')) $app = 'Single Token-Ring functional address';
634
        if (mac_equals($mac, '03:00:00:00:00:08')) $app = 'Configuration Report Server (CRS) MAC Group address';
635
        if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'Ring Error Monitor (REM) MAC Group address';
636
        if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'Ring Parameter Server (RPS) MAC group address';
637
        if (mac_equals($mac, '03:00:00:00:01:00')) $app = 'All Intermediate System Network Entities address';
638
        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';
639
        if (mac_equals($mac, '03:00:00:00:04:00')) $app = 'Generic address for all Manager Stations';
640
        if (mac_equals($mac, '03:00:00:00:08:00')) $app = 'All CONs SNARES address';
641
        if (mac_equals($mac, '03:00:00:00:10:00')) $app = 'All CONs End System address';
642
        if (mac_equals($mac, '03:00:00:00:20:00')) $app = 'Loadable Device Generic address';
643
        if (mac_equals($mac, '03:00:00:00:40:00')) $app = 'Load Server Generic address';
644
        if (mac_equals($mac, '03:00:00:40:00:00')) $app = 'Generic address for all Agent Stations';
645
        if (mac_equals($mac, 'C0:00:00:04:00:00')) $app = 'Single Token-Ring functional address';
646
        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';
647
        if (mac_equals($mac, '03:00:40:00:00:00')) $app = 'IPv6 multicast over Token Ring: all-Routers addresses (FF0X::2)';
648
        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';
649
        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';
650
        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';
651
        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';
652
        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';
653
        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';
654
        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';
655
        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';
656
 
657
        // === FAQ "How to recognise an AppleTalk protocols by MAC address?" ===
658
        // https://tools.ietf.org/html/rfc1060
659
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
660
        if (mac_between($mac, '09:00:07:00:00:00', '09:00:07:00:00:FC')) $app = 'AppleTalk zone multicast addresses (EtherType is 0x0802)';
661
        if (mac_equals($mac, '09:00:07:FF:FF:FF')) $app = 'AppleTalk broadcast address (EtherType is 0x0802)';
662
 
663
        // === FAQ "How to recognise a TRILL protocols by MAC address?" ===
664
        // http://www.iana.org/go/rfc7455
665
        // https://tools.ietf.org/html/draft-ietf-trill-oam-framework-04
666
        // https://standards.ieee.org/products-services/regauth/grpmac/public.html
667
        // https://tools.ietf.org/html/rfc7455#appendix-C
668
        if (mac_between($mac, '00:00:5E:90:01:00', '00:00:5E:90:01:00')) $app = 'TRILL OAM';
669
        if (mac_equals($mac, '01:00:5E:90:01:00')) $app = 'TRILL OAM';
670
        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';
671
 
672
        // === FAQ "How to recognise an IEEE 802.1X MAC address application?" ===
673
        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';
674
        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';
675
        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';
676
        if (mac_equals($mac, '01:1B:19:00:00:00')) $app = 'General group address - An 802.1Q VLAN Bridge would forward the frame unchanged.';
677
        if (mac_equals($mac, '01:1B:19:00:00:00')) $app = 'Precision Time Protocol (PTP) version 2 over Ethernet, EtherType is 0x88F7';
678
        if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Bridge Group address Nearest Customer Bridge group address';
679
        if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Spanning Tree Protocol (for bridges) IEEE 802.1D, EtherType is 0x0802';
680
        if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
681
        if (mac_between($mac, '01:80:C2:00:00:00', '01:80:C2:00:00:0F')) $app = 'The initial bridging/link protocols block';
682
        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';
683
        if (mac_between($mac, '01:80:C2:00:00:00', '01:80:C2:00:00:0F')) $app = 'IEEE Pause, 802.3x';
684
        if (mac_equals($mac, '01:80:C2:00:00:0A')) $app = 'Reserved for future standardization';
685
        if (mac_equals($mac, '01:80:C2:00:00:0B')) $app = 'EDE-SS PEP Address';
686
        if (mac_equals($mac, '01:80:C2:00:00:0C')) $app = 'Reserved for future standardization';
687
        if (mac_equals($mac, '01:80:C2:00:00:0D')) $app = 'Provider Bridge MVRP address';
688
        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';
689
        if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Nearest Bridge group address';
690
        if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
691
        if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Precision Time Protocol (PTP) version 2 over Ethernet, EtherType is 0x88F7';
692
        if (mac_equals($mac, '01:80:C2:00:00:01')) $app = 'IEEE MAC-specific Control Protocols group address';
693
        if (mac_equals($mac, '01:80:C2:00:00:01')) $app = 'Ethernet flow control (Pause frame) IEEE 802.3x, EtherType is 0x8808';
694
        if (mac_equals($mac, '01:80:C2:00:00:1A')) $app = 'Generic Address for All Agent Stations';
695
        if (mac_equals($mac, '01:80:C2:00:00:1B')) $app = 'All Multicast Capable End Systems address';
696
        if (mac_equals($mac, '01:80:C2:00:00:1C')) $app = 'All Multicast Announcements address';
697
        if (mac_equals($mac, '01:80:C2:00:00:1D')) $app = 'All Multicast Capable Intermediate Systems address';
698
        if (mac_equals($mac, '01:80:C2:00:00:1E')) $app = 'All DTR Concentrators MAC group address';
699
        if (mac_equals($mac, '01:80:C2:00:00:1F')) $app = 'EDE-CC PEP Address';
700
        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';
701
        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';
702
        if (mac_equals($mac, '01:80:C2:00:00:03')) $app = 'Nearest non-TPMR Bridge group address IEEE Std 802.1X PAE address';
703
        if (mac_equals($mac, '01:80:C2:00:00:03')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
704
        if (mac_equals($mac, '01:80:C2:00:00:04')) $app = 'IEEE MAC-specific Control Protocols group address';
705
        if (mac_equals($mac, '01:80:C2:00:00:05')) $app = 'Reserved for future standardization';
706
        if (mac_equals($mac, '01:80:C2:00:00:06')) $app = 'Reserved for future standardization';
707
        if (mac_equals($mac, '01:80:C2:00:00:07')) $app = 'MEF Forum ELMI protocol group address';
708
        if (mac_equals($mac, '01:80:C2:00:00:08')) $app = 'Provider Bridge group address';
709
        if (mac_equals($mac, '01:80:C2:00:00:08')) $app = 'Spanning Tree Protocol (for provider bridges) IEEE 802.1ad, EtherType is 0x0802';
710
        if (mac_equals($mac, '01:80:C2:00:00:09')) $app = 'Reserved for future standardization';
711
        if (mac_equals($mac, '01:80:C2:00:00:10')) $app = 'All LANs Bridge Management group address (deprecated)';
712
        if (mac_equals($mac, '01:80:C2:00:00:10')) $app = 'Bridge Management, EtherType is 0x0802';
713
        if (mac_equals($mac, '01:80:C2:00:00:11')) $app = 'Load Server generic address';
714
        if (mac_equals($mac, '01:80:C2:00:00:11')) $app = 'Load Server, EtherType is 0x0802';
715
        if (mac_equals($mac, '01:80:C2:00:00:12')) $app = 'Loadable Device generic address';
716
        if (mac_equals($mac, '01:80:C2:00:00:12')) $app = 'Loadable Device, EtherType is 0x0802';
717
        if (mac_equals($mac, '01:80:C2:00:00:13')) $app = 'Transmission of IEEE 1905.1 control packets';
718
        if (mac_equals($mac, '01:80:C2:00:00:14')) $app = 'All Level 1 Intermediate Systems address';
719
        if (mac_equals($mac, '01:80:C2:00:00:14')) $app = 'OSI Route level 1 (within area), EtherType is 0x0802';
720
        if (mac_equals($mac, '01:80:C2:00:00:15')) $app = 'All Level 2 Intermediate Systems address';
721
        if (mac_equals($mac, '01:80:C2:00:00:15')) $app = 'OSI Route level 2 (between area), EtherType is 0x0802';
722
        if (mac_equals($mac, '01:80:C2:00:00:16')) $app = 'All CONS End Systems address';
723
        if (mac_equals($mac, '01:80:C2:00:00:17')) $app = 'All CONS SNARES address';
724
        if (mac_equals($mac, '01:80:C2:00:00:18')) $app = 'Generic address for All Manager Stations';
725
        if (mac_equals($mac, '01:80:C2:00:00:19')) $app = 'Groupcast with retries (GCR) MAC group address';
726
        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';
727
        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';
728
        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';
729
        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';
730
        if (mac_between($mac, '01:80:C2:00:00:50', '01:80:C2:00:00:FF')) $app = 'Unassigned standard group MAC address';
731
        if (mac_equals($mac, '01:80:C2:00:01:00')) $app = 'Ring Management Directed Beacon multicast address';
732
        if (mac_equals($mac, '01:80:C2:00:01:00')) $app = 'FDDI RMT Directed Beacon, EtherType is 0x0802';
733
        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';
734
        if (mac_equals($mac, '01:80:C2:00:01:10')) $app = 'Status Report Frame Status Report Protocol multicast address';
735
        if (mac_equals($mac, '01:80:C2:00:01:10')) $app = 'FDDI status report frame, EtherType is 0x0802';
736
        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';
737
        if (mac_equals($mac, '01:80:C2:00:01:20')) $app = 'All FDDI Concentrator MACs';
738
        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';
739
        if (mac_equals($mac, '01:80:C2:00:01:30')) $app = 'Synchronous Bandwidth Allocation address';
740
        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';
741
        if (mac_between($mac, '01:80:C2:00:02:00', '01:80:C2:00:02:FF')) $app = 'Assigned to ETSI for future use';
742
        if (mac_between($mac, '01:80:C2:00:03:00', '01:80:C2:FF-FF-FF')) $app = 'Unassigned standard group MAC address';
743
        if (mac_equals($mac, '09:00:4C:00:00:00')) $app = 'BICC 802.1 management, EtherType is 0x0802';
744
        if (mac_equals($mac, '09:00:4C:00:00:0C')) $app = 'BICC Remote bridge STA 802.1(D) Rev8, EtherType is 0x0802';
745
        if (mac_equals($mac, '09:00:4C:00:00:02')) $app = 'BICC 802.1 management, EtherType is 0x0802';
746
        if (mac_equals($mac, '09:00:4C:00:00:06')) $app = 'BICC Local bridge STA 802.1(D) Rev6, EtherType is 0x0802';
747
        if (mac_between($mac, '33:33:00:00:00:00', '33:33:FF:FF:FF:FF')) $app = 'IPv6 multicast, EtherType is 0x86DD';
748
 
749
        // === FAQ "How to recognise an ISO 9542 ES-IS protocol's MAC address application?" ===
750
        // https://standards.ieee.org/products-services/regauth/grpmac/public.html
751
        if (mac_equals($mac, '09:00:2B:00:00:04')) $app = 'All End System Network Entities address';
752
        if (mac_equals($mac, '09:00:2B:00:00:05')) $app = 'All Intermediate System Network Entities address';
753
 
754
        // === FAQ "How to recognise an IANA MAC address application?" ===
755
        // https://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml
756
        // http://www.iana.org/go/rfc7042
757
        // https://tools.ietf.org/html/rfc1060
758
        if (mac_between($mac, '00:00:5E:00-52:14', '00:00:5E:00:52:FF')) $app = 'Unassigned (small allocations)';
759
        if (mac_between($mac, '00:00:5E:00:00:00', '00:00:5E:00:00:FF')) $app = 'Reserved and require IESG Ratification for assignment';
760
        if (mac_between($mac, '00:00:5E:00:03:00', '00:00:5E:00:51:FF')) $app = 'Unassigned';
761
        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.';
762
        if (mac_between($mac, '00:00:5E:00:52:00', '00:00:5E:00:52:00')) $app = 'PacketPWEthA';
763
        if (mac_between($mac, '00:00:5E:00:52:01', '00:00:5E:00:52:01')) $app = 'PacketPWEthB';
764
        if (mac_between($mac, '00:00:5E:00:52:02', '00:00:5E:00:52:12')) $app = 'Unassigned (small allocations)';
765
        if (mac_between($mac, '00:00:5E:00:53:00', '00:00:5E:00:53:FF')) $app = 'Assigned for use in documentation';
766
        if (mac_between($mac, '00:00:5E:00:54:00', '00:00:5E:90:00:FF')) $app = 'Unassigned';
767
        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 768
        if (mac_between($mac, '00:00:5E:EF:10:00:00:00', '00:00:5E:EF:10:00:00:FF')) $app = 'General documentation';
769
        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 770
        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.)
771
        if (mac_between($mac, '01:00:5E:80:00:00', '01:00:5E:FF:FF:FF')) $app = 'DoD Internet';
772
        if (mac_equals($mac, '01:00:5E:90:00:02')) $app = 'AllL1MI-ISs';
773
        if (mac_equals($mac, '01:00:5E:90:00:03')) $app = 'AllL2MI-ISs';
774
        if (mac_between($mac, '01:00:5E:90:00:04', '01:00:5E:90:00:FF')) $app = 'Unassigned (small allocations)';
775
        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)';
776
        if (mac_between($mac, '01:00:5E:90:02:00', '01:00:5E:90:0F:FF')) $app = 'Unassigned';
777
        if (mac_between($mac, '01:00:5E:90:02:00', '00:00:5E:FF:FF:FF')) $app = 'Unassigned';
778
        if (mac_between($mac, '01:00:5E:90:10:00', '01:00:5E:90:10:FF')) $app = 'Documentation';
779
        if (mac_between($mac, '01:00:5E:90:11:00', '01:00:5E:FF:FF:FF')) $app = 'Unassigned';
16 daniel-mar 780
        if (mac_between($mac, '01:00:5E:EF:10:00:00:00', '01:00:5E:EF:10:00:00:FF')) $app = 'General documentation';
781
        if (mac_between($mac, '02:00:5E:00:00:00:00:00', '02:00:5E:0F:FF:FF:FF:FF')) $app = 'Reserved';
782
        if (mac_between($mac, '02:00:5E:10:00:00:00:00', '02:00:5E:10:00:00:00:FF')) $app = 'Documentation';
783
        if (mac_between($mac, '02:00:5E:10:00:00:01:00', '02:00:5E:EF:FF:FF:FF:FF')) $app = 'Unassigned';
784
        if (mac_between($mac, '02:00:5E:F0:00:00:00:00', '02:00:5E:FD:FF:FF:FF:FF')) $app = 'Reserved';
785
        if (mac_between($mac, '02:00:5E:FE:00:00:00:00', '02:00:5E:FE:FF:FF:FF:FF')) $app = 'IPv4 Addr Holders';
786
        if (mac_between($mac, '02:00:5E:FF:00:00:00:00', '02:00:5E:FF:FD:FF:FF:FF')) $app = 'Reserved';
787
        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';
788
        if (mac_between($mac, '02:00:5E:FF:FF:00:00:00', '02:00:5E:FF:FF:FF:FF:FF')) $app = 'Reserved';
789
        if (mac_between($mac, '03:00:5E:00:00:00:00:00', '03:00:5E:0F:FF:FF:FF:FF')) $app = 'Reserved';
790
        if (mac_between($mac, '03:00:5E:10:00:00:00:00', '03:00:5E:10:00:00:00:FF')) $app = 'Documentation';
791
        if (mac_between($mac, '03:00:5E:10:00:00:01:00', '03:00:5E:EF:FF:FF:FF:FF')) $app = 'Unassigned';
792
        if (mac_between($mac, '03:00:5E:F0:00:00:00:00', '03:00:5E:FD:FF:FF:FF:FF')) $app = 'Reserved';
793
        if (mac_between($mac, '03:00:5E:FF:00:00:00:00', '03:00:5E:FF:FD:FF:FF:FF')) $app = 'Reserved';
794
        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';
795
        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 796
 
797
        // === FAQ "How to recognise a Cisco's MAC address application?" ===
798
        // https://www.cisco.com/c/en/us/support/docs/switches/catalyst-4500-series-switches/13414-103.html
799
        // https://tools.ietf.org/html/rfc1060
800
        // https://en.wikipedia.org/wiki/Multicast_address#cite_note-15
801
        // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
802
        if (mac_equals($mac, '01:00:0C:00:00:00')) $app = 'Inter Switch Link (ISL)';
803
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'CDP (Cisco Discovery Protocol), VTP (VLAN Trunking Protocol), EtherType is 0x0802';
804
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Port Aggregation Protocol (PAgP), SNAP HDLC Protocol Type is 0x0104';
805
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Unidirectional Link Detection (UDLD), SNAP HDLC Protocol Type is 0x0111';
806
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Dynamic Trunking (DTP), SNAP HDLC Protocol Type is 0x2004';
807
        if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'VLAN Trunking (VTP), SNAP HDLC Protocol Type is 0x2003';
808
        if (mac_equals($mac, '01:00:0C:CC:CC:CD')) $app = 'Cisco Shared Spanning Tree Protocol address, EtherType is 0x0802';
809
        if (mac_equals($mac, '01:00:0C:CC:CC:CD')) $app = 'Spanning Tree PVSTP+, SNAP HDLC Protocol Type is 0x010B';
810
        if (mac_equals($mac, '01:00:0C:CD:CD:CD')) $app = 'STP Uplink Fast, SNAP HDLC Protocol Type is 0x200A';
811
        if (mac_equals($mac, '01:00:0C:CD:CD:CE')) $app = 'VLAN Bridge, SNAP HDLC Protocol Type is 0x010C';
812
        if (mac_equals($mac, '01:00:0C:DD:DD:DD')) $app = 'CGMP (Cisco Group Management Protocol)';
813
 
814
        // === FAQ "How to recognise an ITU-T's MAC address application?" ===
815
        // https://www.itu.int/en/ITU-T/studygroups/2017-2020/15/Documents/IEEE-assigned_OUIs-30-06-2017.docx
816
        if (mac_between($mac, '01:19:A7:00:00:00', '01:19:A7:00:00:FF')) $app = 'R-APS per G.8032';
817
        if (mac_between($mac, '01:19:A7:52:76:90', '01:19:A7:52:76:9F')) $app = 'Multicast per G.9961';
818
 
819
        // === FAQ "How to recognise Digital Equipment Corporation's MAC address application?" ===
820
        if (mac_equals($mac, '09:00:2B:00:00:00')) $app = 'DEC MUMPS, EtherType is 0x6009';
821
        if (mac_equals($mac, '09:00:2B:00:00:0F')) $app = 'DEC Local Area Transport (LAT), EtherType is 0x6004';
822
        if (mac_equals($mac, '09:00:2B:00:00:01')) $app = 'DEC DSM/DDP, EtherType is 0x8039';
823
        if (mac_between($mac, '09:00:2B:00:00:10', '09:00:2B:00:00:1F')) $app = 'DEC Experimental';
824
        if (mac_equals($mac, '09:00:2B:00:00:02')) $app = 'DEC VAXELN, EtherType is 0x803B';
825
        if (mac_equals($mac, '09:00:2B:00:00:03')) $app = 'DEC Lanbridge Traffic Monitor (LTM), EtherType is 0x8038';
826
        if (mac_equals($mac, '09:00:2B:00:00:04')) $app = 'DEC MAP End System';
827
        if (mac_equals($mac, '09:00:2B:00:00:05')) $app = 'DEC MAP Intermediate System';
828
        if (mac_equals($mac, '09:00:2B:00:00:06')) $app = 'DEC CSMA/CD Encryption, EtherType is 0x803D';
829
        if (mac_equals($mac, '09:00:2B:00:00:07')) $app = 'DEC NetBios Emulator, EtherType is 0x8040';
830
        if (mac_equals($mac, '09:00:2B:01:00:00')) $app = 'DEC LanBridge, EtherType is 0x8038';
831
        if (mac_equals($mac, '09:00:2B:01:00:01')) $app = 'DEC LanBridge, EtherType is 0x8038';
832
        if (mac_equals($mac, '09:00:2B:02:00:00')) $app = 'DEC DNA Level 2 Routing';
833
        if (mac_equals($mac, '09:00:2B:02:01:00')) $app = 'DEC DNA Naming Service Advertisement, EtherType is 0x803C';
834
        if (mac_equals($mac, '09:00:2B:02:01:01')) $app = 'DEC DNA Naming Service Solicitation, EtherType is 0x803C';
835
        if (mac_equals($mac, '09:00:2B:02:01:02')) $app = 'DEC Distributed Time Service, EtherType is 0x803E';
836
        if (mac_equals($mac, '09:00:2B:02:01:09')) $app = 'DEC Availability Manager for Distributed Systems DECamds, EtherType is 0x8048';
837
        if (mac_between($mac, '09:00:2B:03:00:00', '09:00:2B:03:FF:FF')) $app = 'DEC default filtering by bridges';
838
        if (mac_equals($mac, '09:00:2B:04:00:00')) $app = 'DEC Local Area System Transport (LAST), EtherType is 0x8041';
839
        if (mac_equals($mac, '09:00:2B:23:00:00')) $app = 'DEC Argonaut Console, EtherType is 0x803A';
840
        if (mac_equals($mac, 'AB:00:00:01:00:00')) $app = 'DEC Maintenance Operation Protocol (MOP) Dump/Load Assistance, EtherType is 0x6001';
841
        if (mac_equals($mac, 'AB:00:00:02:00:00')) $app = 'DEC Maintenance Operation Protocol (MOP), EtherType is 0x6002';
842
        if (mac_equals($mac, 'AB:00:00:03:00:00')) $app = 'DECNET Phase IV end node, EtherType is 0x6003';
843
        if (mac_equals($mac, 'AB:00:00:04:00:00')) $app = 'DECNET Phase IV Router, EtherType is 0x6003';
844
        if (mac_between($mac, 'AB:00:00:05:00:00', 'AB:00:03:FF:FF:FF')) $app = 'Reserved DEC';
845
        if (mac_equals($mac, 'AB:00:03:00:00:00')) $app = 'DEC Local Area Transport (LAT) - old, EtherType is 0x6004';
846
        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 847
        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 848
 
21 daniel-mar 849
        // https://standards.ieee.org/products-programs/regauth/grpmac/public/
850
        // TODO: Check for duplicates between these and the ones at the top
851
        // IEEE Std 802.1D and IEEE Std 802.1Q Reserved Addresses
852
        if (mac_equals($mac, '01-80-C2-00-00-00')) $app = 'IEEE Std 802.1Q / Bridge Group address, Nearest Customer Bridge group address';
853
        if (mac_equals($mac, '01-80-C2-00-00-01')) $app = 'IEEE Std 802.1Q / IEEE MAC-specific Control Protocols group address';
854
        if (mac_equals($mac, '01-80-C2-00-00-02')) $app = 'IEEE Std 802.1Q / IEEE 802.3 Slow_Protocols_Multicast address';
855
        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';
856
        if (mac_equals($mac, '01-80-C2-00-00-04')) $app = 'IEEE Std 802.1Q / IEEE MAC-specific Control Protocols group address';
857
        if (mac_equals($mac, '01-80-C2-00-00-05')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
858
        if (mac_equals($mac, '01-80-C2-00-00-06')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
859
        if (mac_equals($mac, '01-80-C2-00-00-07')) $app = 'IEEE Std 802.1Q / MEF Forum ELMI protocol group address';
860
        if (mac_equals($mac, '01-80-C2-00-00-08')) $app = 'IEEE Std 802.1Q / Provider Bridge group address';
861
        if (mac_equals($mac, '01-80-C2-00-00-09')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
862
        if (mac_equals($mac, '01-80-C2-00-00-0A')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
863
        if (mac_equals($mac, '01-80-C2-00-00-0B')) $app = 'IEEE Std 802.1Q / EDE-SS PEP Address';
864
        if (mac_equals($mac, '01-80-C2-00-00-0C')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
865
        if (mac_equals($mac, '01-80-C2-00-00-0D')) $app = 'IEEE Std 802.1Q / Provider Bridge MVRP address';
866
        if (mac_equals($mac, '01-80-C2-00-00-0E')) $app = 'IEEE Std 802.1Q / Individual LAN Scope group address, Nearest Bridge group address';
867
        if (mac_equals($mac, '01-80-C2-00-00-0F')) $app = 'IEEE Std 802.1Q / Reserved for future standardization';
868
        // Standard Group MAC Addresses
869
        if (mac_equals($mac, '01-80-C2-00-00-10')) $app = 'All LANs Bridge Management Group Address (deprecated)';
870
        if (mac_equals($mac, '01-80-C2-00-00-11')) $app = 'Load Server Generic Address';
871
        if (mac_equals($mac, '01-80-C2-00-00-12')) $app = 'Loadable Device Generic Address';
872
        if (mac_equals($mac, '01-80-C2-00-00-13')) $app = 'Transmission of IEEE 1905.1 control packets';
873
        if (mac_equals($mac, '01-80-C2-00-00-14')) $app = 'All Level 1 Intermediate Systems Address';
874
        if (mac_equals($mac, '01-80-C2-00-00-15')) $app = 'All Level 2 Intermediate Systems Address';
875
        if (mac_equals($mac, '01-80-C2-00-00-16')) $app = 'All CONS End Systems Address';
876
        if (mac_equals($mac, '01-80-C2-00-00-17')) $app = 'All CONS SNARES Address';
877
        if (mac_equals($mac, '01-80-C2-00-00-18')) $app = 'Generic Address for All Manager Stations';
878
        if (mac_equals($mac, '01-80-C2-00-00-19')) $app = 'Groupcast with retries (GCR) MAC Group Address';
879
        if (mac_equals($mac, '01-80-C2-00-00-1A')) $app = 'Generic Address for All Agent Stations';
880
        if (mac_equals($mac, '01-80-C2-00-00-1B')) $app = 'All Multicast Capable End Systems Address';
881
        if (mac_equals($mac, '01-80-C2-00-00-1C')) $app = 'All Multicast Announcements Address';
882
        if (mac_equals($mac, '01-80-C2-00-00-1D')) $app = 'All Multicast Capable Intermediate Systems Address';
883
        if (mac_equals($mac, '01-80-C2-00-00-1E')) $app = 'All DTR Concentrators MAC Group Address';
884
        if (mac_equals($mac, '01-80-C2-00-00-1F')) $app = 'EDE-CC PEP Address';
885
        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';
886
        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';
887
        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';
888
        if (mac_between($mac, '01-80-C2-00-00-50','01-80-C2-00-00-FF')) $app = 'unassigned';
889
        if (mac_equals($mac, '01-80-C2-00-01-00')) $app = 'Ring Management Directed Beacon Multicast Address';
890
        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';
891
        if (mac_equals($mac, '01-80-C2-00-01-10')) $app = 'Status Report Frame Status Report Protocol Multicast Address';
892
        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';
893
        if (mac_equals($mac, '01-80-C2-00-01-20')) $app = 'ISO/IEC 9314-2 All FDDI Concentrator MACs';
894
        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';
895
        if (mac_equals($mac, '01-80-C2-00-01-30')) $app = 'ISO/IEC 9314-6 Synchronous Bandwidth Allocation Address';
896
        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';
897
        if (mac_between($mac, '01-80-C2-00-02-00','01-80-C2-00-02-FF')) $app = 'Assigned to ETSI for future use';
898
        if (mac_between($mac, '01-80-C2-00-03-00', '01-80-C2-FF-FF-FF')) $app = 'unassigned';
899
        if (mac_equals($mac, '09-00-2B-00-00-04')) $app = 'ISO 9542 All End System Network Entities Address';
900
        if (mac_equals($mac, '09-00-2B-00-00-05')) $app = 'ISO 9542 All Intermediate System Network Entities Address';
901
        // Group MAC Addresses Used in ISO 9542 ES-IS Protocol
902
        if (mac_equals($mac, '09-00-2B-00-00-04')) $app = 'ISO 9542 All End System Network Entities Address';
903
        if (mac_equals($mac, '09-00-2B-00-00-05')) $app = 'ISO 9542 All Intermediate System Network Entities Address';
904
        // Locally Administered Group MAC Addresses Used by IEEE Std 802.5 (IEEE Std 802.5 Functional Addresses)
905
        if (mac_equals($mac, '03-00-00-00-00-08')) $app = 'Configuration Report Server (CRS) MAC Group Address';
906
        if (mac_equals($mac, '03-00-00-00-00-10')) $app = 'Ring Error Monitor (REM) MAC Group Address';
907
        if (mac_equals($mac, '03-00-00-00-00-40')) $app = 'Ring Parameter Server (RPS) MAC Group Address';
908
        if (mac_equals($mac, '03-00-00-00-01-00')) $app = 'All Intermediate System Network Entities Address';
909
        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';
910
        if (mac_equals($mac, '03-00-00-00-04-00')) $app = 'Generic Address for all Manager Stations';
911
        if (mac_equals($mac, '03-00-00-00-08-00')) $app = 'All CONs SNARES Address';
912
        if (mac_equals($mac, '03-00-00-00-10-00')) $app = 'All CONs End System Address';
913
        if (mac_equals($mac, '03-00-00-00-20-00')) $app = 'Loadable Device Generic Address';
914
        if (mac_equals($mac, '03-00-00-00-40-00')) $app = 'Load Server Generic Address';
915
        if (mac_equals($mac, '03-00-00-40-00-00')) $app = 'Generic Address for all Agent Stations';
916
 
15 daniel-mar 917
        if ($app) {
918
                echo sprintf("%-32s %s\n", "Special use:", $app);
919
        }
920
 
2 daniel-mar 921
}
15 daniel-mar 922
 
923
/**
924
 * @param string $mac1
925
 * @param string $mac2
926
 * @return bool
927
 */
928
function mac_equals(string $mac1, string $mac2): bool {
16 daniel-mar 929
        $mac1test = eui64_to_eui48($mac1);
930
        if ($mac1test === false) return false;
931
        $mac2test = eui64_to_eui48($mac2);
932
        if ($mac2test === false) return false;
933
 
934
        if (eui_bits($mac1test) != eui_bits($mac2test)) {
935
                $mac1test = eui48_to_eui64($mac1);
936
                $mac2test = eui48_to_eui64($mac2);
937
        }
938
 
939
        return mac_canonize($mac1test) == mac_canonize($mac2test);
15 daniel-mar 940
}
941
 
942
/**
943
 * @param string $mac
944
 * @param string $low
945
 * @param string $high
946
 * @return bool
947
 */
948
function mac_between(string $mac, string $low, string $high): bool {
16 daniel-mar 949
        $mactest = eui64_to_eui48($mac);
950
        if ($mactest === false) return false;
951
        $lowtest = eui64_to_eui48($low);
952
        if ($lowtest === false) return false;
953
        $hightest = eui64_to_eui48($high);
954
        if ($hightest === false) return false;
15 daniel-mar 955
 
16 daniel-mar 956
        if ((eui_bits($mactest) != eui_bits($lowtest)) || (eui_bits($lowtest) != eui_bits($hightest))) {
957
                $mactest = eui48_to_eui64($mac);
18 daniel-mar 958
                if ($mactest === false) return false; // e.g. trying ELI-48 to ELI-64
16 daniel-mar 959
                $lowtest = eui48_to_eui64($low);
18 daniel-mar 960
                if ($lowtest === false) return false; // e.g. trying ELI-48 to ELI-64
16 daniel-mar 961
                $hightest = eui48_to_eui64($high);
18 daniel-mar 962
                if ($hightest === false) return false; // e.g. trying ELI-48 to ELI-64
16 daniel-mar 963
        }
15 daniel-mar 964
 
16 daniel-mar 965
        $mactest = strtoupper(preg_replace('@[^0-9A-F]@', '', $mactest));
966
        $lowtest = strtoupper(preg_replace('@[^0-9A-F]@', '', $lowtest));
967
        $hightest = strtoupper(preg_replace('@[^0-9A-F]@', '', $hightest));
15 daniel-mar 968
 
16 daniel-mar 969
        $mactest = gmp_init($mactest, 16);
970
        $lowtest = gmp_init($lowtest, 16);
971
        $hightest = gmp_init($hightest, 16);
15 daniel-mar 972
 
16 daniel-mar 973
        return (gmp_cmp($mactest, $lowtest) >= 0) && (gmp_cmp($mactest, $hightest) <= 0);
17 daniel-mar 974
}