Subversion Repositories uuid_mac_utils

Rev

Rev 15 | Rev 17 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * MAC (EUI-48 and EUI-64) utils for PHP
  5.  * Copyright 2017 - 2023 Daniel Marschall, ViaThinkSoft
  6.  * Version 2023-04-29
  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.  
  21. const IEEE_MAC_REGISTRY = __DIR__ . '/../web-data';
  22.  
  23. /**
  24.  * @param string $mac
  25.  * @return bool
  26.  */
  27. function mac_valid(string $mac): bool {
  28.         $tmp = ipv6linklocal_to_eui64($mac);
  29.         if ($tmp !== false) $mac = $tmp;
  30.  
  31.         $mac = str_replace(array('-', ':'), '', $mac);
  32.         $mac = strtoupper($mac);
  33.  
  34.         if ((strlen($mac) != 12) && (strlen($mac) != 16)) return false;
  35.  
  36.         $mac = preg_replace('@[0-9A-F]@', '', $mac);
  37.  
  38.         return ($mac === '');
  39. }
  40.  
  41. /**
  42.  * @param string $mac
  43.  * @param string $delimiter
  44.  * @return string|false
  45.  */
  46. function mac_canonize(string $mac, string $delimiter="-") {
  47.         if (!mac_valid($mac)) return false;
  48.  
  49.         $tmp = ipv6linklocal_to_eui64($mac);
  50.         if ($tmp !== false) $mac = $tmp;
  51.  
  52.         $mac = strtoupper($mac);
  53.         $mac = preg_replace('@[^0-9A-F]@', '', $mac);
  54.         if ((strlen($mac) != 12) && (strlen($mac) != 16)) return false;
  55.         $mac = preg_replace('@^(..)(..)(..)(..)(..)(..)(..)(..)$@', '\\1'.$delimiter.'\\2'.$delimiter.'\\3'.$delimiter.'\\4'.$delimiter.'\\5'.$delimiter.'\\6'.$delimiter.'\\7'.$delimiter.'\\8', $mac);
  56.         return preg_replace('@^(..)(..)(..)(..)(..)(..)$@', '\\1'.$delimiter.'\\2'.$delimiter.'\\3'.$delimiter.'\\4'.$delimiter.'\\5'.$delimiter.'\\6', $mac);
  57. }
  58.  
  59. /**
  60.  * @param string $file
  61.  * @param string $oui_name
  62.  * @param string $mac
  63.  * @return false|string
  64.  */
  65. function _lookup_ieee_registry(string $file, string $oui_name, string $mac) {
  66.         $mac = mac_canonize($mac, '');
  67.         if ($mac === false) return false;
  68.         $begin = substr($mac, 0, 2).'-'.substr($mac, 2, 2).'-'.substr($mac, 4, 2);
  69.         $f = file_get_contents($file);
  70.  
  71.         $f = str_replace("\r", '', $f);
  72.  
  73.         # We are using a positive-lookahead because entries like the MA-M references have a blank line between organization and address
  74.         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);
  75.         foreach ($m as $n) {
  76.                 preg_match('@(\S+)\s+\(base 16\)(.*)$@ism', $n[2], $m);
  77.  
  78.                 if (preg_match('@(.+)-(.+)@ism', $m[1], $o)) {
  79.                         $z = hexdec(substr($mac, 6, 6));
  80.                         $beg = hexdec($o[1]);
  81.                         $end = hexdec($o[2]);
  82.                         if (($z < $beg) || ($z > $end)) continue;
  83.                 } else {
  84.                         $beg = 0x000000;
  85.                         $end = 0xFFFFFF;
  86.                 }
  87.  
  88.                 $x = trim(preg_replace('@^\s+@im', '', $m[2]));
  89.  
  90.                 # "PRIVATE" entries are only marked at the "(hex)" line, but not at the "(base16)" line
  91.                 if ($x == '') $x = trim($n[1]);
  92.  
  93.                 $x = explode("\n", $x);
  94.  
  95.                 $ra_len = strlen(dechex($end-$beg));
  96.  
  97.                 $out = sprintf("%-32s 0x%s\n", "IEEE $oui_name part:", substr($mac, 0, 12-$ra_len));
  98.                 $out .= sprintf("%-32s 0x%s\n", "NIC specific part:", substr($mac, 12-$ra_len));
  99.                 $out .= sprintf("%-32s %s\n", "Registrant:", $x[0]);
  100.                 foreach ($x as $n => $y) {
  101.                         if ($n == 0) continue;
  102.                         else if ($n == 1) $out .= sprintf("%-32s %s\n", "Address of registrant:", $y);
  103.                         else if ($n >= 2) $out .= sprintf("%-32s %s\n", "", $y);
  104.                 }
  105.  
  106.                 // TODO: also print the date of last update of the OUI files
  107.  
  108.                 return $out;
  109.         }
  110.  
  111.         return false;
  112. }
  113.  
  114. /**
  115.  * @param string $eui64
  116.  * @return false|string If EUI-64 can be converted into EUI-48 (if it has FFFE in the middle), returns EUI-48, otherwise returns EUI-64. On invalid input, return false.
  117.  */
  118. function eui64_to_eui48(string $eui64) {
  119.         if (!mac_valid($eui64)) return false;
  120.         $eui64 = mac_canonize($eui64, '');
  121.         if (eui_bits($eui64) == 48) return mac_canonize($eui64);
  122.  
  123.         if (substr($eui64, 6, 4) == 'FFFE') {
  124.                 return mac_canonize(substr($eui64, 0, 6).substr($eui64, 10, 6));
  125.         } else {
  126.                 return mac_canonize($eui64);
  127.         }
  128. }
  129.  
  130. /**
  131.  * @param string $eui48
  132.  * @return false|string
  133.  */
  134. function eui48_to_eui64(string $eui48) {
  135.         if (!mac_valid($eui48)) return false;
  136.         $eui48 = mac_canonize($eui48, '');
  137.         if (eui_bits($eui48) == 64) return mac_canonize($eui48);
  138.  
  139.         $eui64 = substr($eui48, 0, 6).'FFFE'.substr($eui48, 6, 6);
  140.         return mac_canonize($eui64);
  141. }
  142.  
  143. /**
  144.  * @param string $ipv6
  145.  * @return false|string
  146.  */
  147. function ipv6linklocal_to_eui64(string $ipv6) {
  148.         // https://stackoverflow.com/questions/12095835/quick-way-of-expanding-ipv6-addresses-with-php (modified)
  149.         $tmp = inet_pton($ipv6);
  150.         if ($tmp === false) return false;
  151.         $hex = unpack("H*hex", $tmp);
  152.         $ipv6 = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1);
  153.  
  154.         // Remove "fe80::" to convert IPv6 Link Local address back to EUI-64
  155.         // see https://support.lenovo.com/de/de/solutions/ht509925-how-to-convert-a-mac-address-into-an-ipv6-link-local-address-eui-64
  156.         $cnt = 0;
  157.         $mac = preg_replace('@^fe80:0000:0000:0000:@i', '', $ipv6, -1, $cnt);
  158.         if ($cnt == 0) return false;
  159.  
  160.         // Set LAA to UAA again
  161.         $mac[1] = dechex(hexdec($mac[1]) & 253);
  162.  
  163.         return eui64_to_eui48($mac);
  164. }
  165.  
  166. /**
  167.  * @param string $mac
  168.  * @return false|int
  169.  */
  170. function eui_bits(string $mac) {
  171.         if (!mac_valid($mac)) return false;
  172.         $mac = mac_canonize($mac, '');
  173.         return (int)(strlen($mac)*4);
  174. }
  175.  
  176. /**
  177.  * @param string $mac
  178.  * @return false|string
  179.  */
  180. function eui_to_ipv6linklocal(string $mac) {
  181.         if (!mac_valid($mac)) return false;
  182.         if (eui_bits($mac) == 48) {
  183.                 $mac = eui48_to_eui64($mac);
  184.         }
  185.         $mac = mac_canonize($mac, '');
  186.  
  187.         $mac[1] = dechex(hexdec($mac[1]) | 2);
  188.  
  189.         $mac = str_pad($mac, 16, '0', STR_PAD_LEFT);
  190.         return strtolower('fe80::'.substr($mac,0, 4).':'.substr($mac,4, 4).':'.substr($mac,8, 4).':'.substr($mac,12, 4));
  191. }
  192.  
  193. /**
  194.  * @param string $mac
  195.  * @return void
  196.  * @throws Exception
  197.  */
  198. function decode_mac(string $mac) {
  199.         // Amazing website about MAC addresses: https://mac-address.alldatafeeds.com/faq#how-to-recognise-mac-address-application
  200.  
  201.         echo sprintf("%-32s %s\n", "Input:", $mac);
  202.  
  203.         $type = '';
  204.         $tmp = ipv6linklocal_to_eui64($mac);
  205.         if ($tmp !== false) {
  206.                 $mac = $tmp;
  207.                 $type = 'IPv6-Link-Local';
  208.         }
  209.         if (!mac_valid($mac)) throw new Exception("Invalid MAC address");
  210.         if ($tmp === false) {
  211.                 // Size
  212.                 $type = eui_bits($mac)==48 ? 'EUI-48 (6 Byte)' : 'EUI-64 (8 Byte)';
  213.         }
  214.         echo sprintf("%-32s %s\n", "Type:", $type);
  215.  
  216.         echo "\n";
  217.  
  218.         // Format MAC
  219.         $mac = mac_canonize($mac, '');
  220.  
  221.         // Show various representations
  222.         $eui48 = eui64_to_eui48($mac);
  223.         echo sprintf("%-32s %s\n", "EUI-48:", (eui_bits($eui48) != 48) ? 'Not available' : $eui48);
  224.         $eui64 = eui48_to_eui64($mac);
  225.         echo sprintf("%-32s %s\n", "EUI-64:", (eui_bits($eui64) != 64) ? 'Not available' : $eui64);
  226.         $ipv6 = eui_to_ipv6linklocal($mac);
  227.         echo sprintf("%-32s %s\n", "IPv6 link local address:", $ipv6);
  228.  
  229.         // Vergabestelle
  230.         $ul = hexdec($mac[1]) & 2; // Bit #LSB+1 of Byte 1
  231.         $ul_ = ($ul == 0) ? '[0] Universally Administered Address (UAA)' : '[1] Locally Administered Address (LAA)';
  232.         echo sprintf("%-32s %s\n", "Administration type (U/L flag):", $ul_);
  233.  
  234.         // Empfaengergruppe
  235.         $ig = hexdec($mac[1]) & 1; // Bit #LSB+0 of Byte 1
  236.         $ig_ = ($ig == 0) ? '[0] Individual (Unicast)' : '[1] Group (Multicast)';
  237.         echo sprintf("%-32s %s\n", "Transmission type (I/G flag):", $ig_);
  238.  
  239.         // Query IEEE registries
  240.         // TODO: gilt OUI nur bei Individual UAA?
  241.         if (count(glob(IEEE_MAC_REGISTRY.'/*.txt')) > 0) {
  242.                 if (
  243.                         # 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]
  244.                         # 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.
  245.                         ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . '/iab.txt', 'IAB', $mac)) ||
  246.                         ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . '/oui36.txt', 'OUI-36 (MA-S)', $mac)) ||
  247.                         ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . '/mam.txt', 'OUI-28 (MA-M)', $mac)) ||
  248.                         ($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . '/oui.txt', 'OUI-24 (MA-L)', $mac))
  249.                 ) {
  250.                         echo $x;
  251.                 }
  252.         }
  253.  
  254.         $vm = '';
  255.         // === FAQ "Detection rules which don't have their dedicated page yet" ===
  256.         // https://wiki.xenproject.org/wiki/Xen_Networking
  257.         // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
  258.         // https://www.techrepublic.com/blog/data-center/mac-address-scorecard-for-common-virtual-machine-platforms
  259.         if (mac_between($mac, '00:16:3E:00:00:00', '00:16:3E:FF:FF:FF')) $vm = "Red Hat Xen, XenSource, Novell Xen";
  260.         // http://techgenix.com/mac-address-pool-duplication-hyper-v/
  261.         // https://docs.microsoft.com/en-us/system-center/vmm/network-mac?view=sc-vmm-1807
  262.         // https://blogs.technet.microsoft.com/gbanin/2014/08/27/how-to-solve-mac-address-conflict-on-hyper-v/
  263.         if (mac_between($mac, '00:1D:D8:B7:1C:00', '00:1D:D8:F4:1F:FF')) $vm = "Microsoft SCVMM (System Center Virtual Machine Manager)";
  264.         // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
  265.         // https://www.techrepublic.com/blog/data-center/mac-address-scorecard-for-common-virtual-machine-platforms/
  266.         // https://blogs.technet.microsoft.com/medv/2011/01/24/how-to-manage-vm-mac-addresses-with-the-globalimagedata-xml-file-in-med-v-v1/
  267.         if (mac_between($mac, '00:03:FF:00:00:00', '00:03:FF:FF:FF:FF')) $vm = "Microsoft Virtual PC / Virtual Server";
  268.         // https://mcpmag.com/articles/2007/11/27/hey-vm-whats-your-hypervisor.aspx
  269.         if (mac_between($mac, '00:18:51:00:00:00', '00:18:51:FF:FF:FF')) $vm = "SWsoft";
  270.         // https://macaddress.io/statistics/company/17619
  271.         if (mac_between($mac, '58:9C:FC:00:00:00', '58:9C:FC:FF:FF:FF')) $vm = "bhyve by FreebsdF";
  272.         // https://macaddress.io/statistics/company/17388
  273.         if (mac_between($mac, '50:6B:8D:00:00:00', '50:6B:8D:FF:FF:FF')) $vm = "Nutanix AHV";
  274.         // https://www.centos.org/forums/viewtopic.php?t=26739
  275.         if (mac_between($mac, '54:52:00:00:00:00', '54:52:FF:FF:FF:FF')) $vm = "KVM (proxmox)";
  276.         // Self tested (alldatafeeds.com)
  277.         if (mac_between($mac, '96:00:00:00:00:00', '96:00:FF:FF:FF:FF')) $vm = "Hetzner vServer (based on KVM and libvirt)";
  278.         // === FAQ "How to recognise a VMware's virtual machine by its MAC address?" ===
  279.         if (mac_between($mac, '00:50:56:00:00:00', '00:50:56:FF:FF:FF')) $vm = "VMware vSphere, VMware Workstation, VMware ESX Server";
  280.         if (mac_between($mac, '00:50:56:80:00:00', '00:50:56:BF:FF:FF')) $vm = "VMware vSphere managed by vCenter Server";
  281.         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";
  282.         if (mac_between($mac, '00:05:69:00:00:00', '00:05:69:FF:FF:FF')) $vm = "VMware ESX, VMware GSX Server";
  283.         if (mac_between($mac, '00:1C:14:00:00:00', '00:1C:14:FF:FF:FF')) $vm = "VMWare";
  284.         // === FAQ "machine by its MAC address?" ===
  285.         if (mac_between($mac, '00:1C:42:00:00:00', '00:1C:42:FF:FF:FF')) $vm = "Parallels Virtual Machine";
  286.         // === FAQ "How to recognise a Docker container by its MAC address?" ===
  287.         if (mac_between($mac, '02:42:00:00:00:00', '02:42:FF:FF:FF:FF')) $vm = "Docker container";
  288.         // === FAQ =How to recognise a Microsoft Hyper-V's virtual machine by its MAC address?" ===
  289.         if (mac_between($mac, '00:15:5D:00:00:00', '00:15:5D:FF:FF:FF')) $vm = "Microsoft Hyper-V";
  290.         // === FAQ "How to recognise an Oracle Virtual machine by its MAC address?" ===
  291.         if (mac_between($mac, '08:00:27:00:00:00', '08:00:27:FF:FF:FF')) $vm = "Oracle VirtualBox 5.2"; // Pcs Systemtechnik GmbH
  292.         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)
  293.         if (mac_between($mac, '00:21:F6:00:00:00', '00:21:F6:FF:FF:FF')) $vm = "Oracle VirtualBox 3.3";
  294.         if (mac_between($mac, '00:14:4F:00:00:00', '00:14:4F:FF:FF:FF')) $vm = "Oracle VM Server for SPARC";
  295.         if (mac_between($mac, '00:0F:4B:00:00:00', '00:0F:4B:FF:FF:FF')) $vm = "Oracle Virtual Iron 4";
  296.  
  297.         if ($vm) {
  298.                 echo sprintf("%-32s %s\n", "Special use:", "Virtual machine $vm");
  299.         }
  300.  
  301.         $app = '';
  302.  
  303.         // === FAQ "Other MAC address applications"
  304.         // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
  305.         // https://tools.ietf.org/html/rfc1060
  306.         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';
  307.         if (mac_equals($mac, '01:00:1D:00:00:00')) $app = 'Cabletron PC-OV PC discover (on demand), EtherType is 0x0802';
  308.         if (mac_equals($mac, '01:00:1D:42:00:00')) $app = 'Cabletron PC-OV Bridge discover (on demand), EtherType is 0x0802';
  309.         if (mac_equals($mac, '01:00:1D:52:00:00')) $app = 'Cabletron PC-OV MMAC discover (on demand), EtherType is 0x0802';
  310.         if (mac_between($mac, '01:00:3C:00:00:00' , '01:00:3C:FF:FF:FF')) $app = 'Auspex Systems (Serverguard)';
  311.         if (mac_equals($mac, '01:00:10:00:00:20')) $app = 'Hughes Lan Systems Terminal Server S/W download, EtherType is 0x0802';
  312.         if (mac_equals($mac, '01:00:10:FF:FF:20')) $app = 'Hughes Lan Systems Terminal Server S/W request, EtherType is 0x0802';
  313.         if (mac_equals($mac, '01:00:81:00:00:00')) $app = 'Synoptics Network Management';
  314.         if (mac_equals($mac, '01:00:81:00:00:02')) $app = 'Synoptics Network Management';
  315.         if (mac_equals($mac, '01:00:81:00:01:00')) $app = 'Bay Networks (Synoptics) autodiscovery, EtherType is 0x0802 SNAP type is 0x01A2';
  316.         if (mac_equals($mac, '01:00:81:00:01:01')) $app = 'Bay Networks (Synoptics) autodiscovery, EtherType is 0x0802 SNAP type is 0x01A1';
  317.         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';
  318.         if (mac_equals($mac, '01:80:24:00:00:00')) $app = 'Kalpana Etherswitch every 60 seconds, EtherType is 0x0802';
  319.         if (mac_equals($mac, '01:DD:00:FF:FF:FF')) $app = 'Ungermann-Bass boot-me requests, EtherType is 0x7002';
  320.         if (mac_equals($mac, '01:DD:01:00:00:00')) $app = 'Ungermann-Bass Spanning Tree, EtherType is 0x7005';
  321.         if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'OS/2 1.3 EE + Communications Manager, EtherType is 0x80D5';
  322.         if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'OS/2 1.3 EE + Communications Manager, EtherType is 0x80D5';
  323.         if (mac_equals($mac, '03:00:00:00:01:00')) $app = 'OSI All-IS Multicast, EtherType is 0x0802';
  324.         if (mac_equals($mac, '03:00:00:00:02:00')) $app = 'OSI All-ES Multicast, EtherType is 0x0802';
  325.         if (mac_equals($mac, '03:00:00:80:00:00')) $app = 'Discovery Client, EtherType is 0x0802';
  326.         if (mac_equals($mac, '03:00:FF:FF:FF:FF')) $app = 'All Stations address, EtherType is 0x0802';
  327.         if (mac_between($mac, '09:00:0D:00:00:00', '09:00:0D:FF:FF:FF')) $app = 'ICL Oslan Multicast, EtherType is 0x0802';
  328.         if (mac_equals($mac, '09:00:0D:02:00:00')) $app = 'ICL Oslan Service discover only on boot';
  329.         if (mac_equals($mac, '09:00:0D:02:0A:3C')) $app = 'ICL Oslan Service discover only on boot';
  330.         if (mac_equals($mac, '09:00:0D:02:0A:38')) $app = 'ICL Oslan Service discover only on boot';
  331.         if (mac_equals($mac, '09:00:0D:02:0A:39')) $app = 'ICL Oslan Service discover only on boot';
  332.         if (mac_equals($mac, '09:00:0D:02:FF:FF')) $app = 'ICL Oslan Service discover only on boot';
  333.         if (mac_equals($mac, '09:00:0D:09:00:00')) $app = 'ICL Oslan Service discover as required';
  334.         if (mac_equals($mac, '09:00:1E:00:00:00')) $app = 'Apollo DOMAIN, EtherType is 0x8019';
  335.         if (mac_equals($mac, '09:00:02:04:00:01')) $app = 'Vitalink printer messages, EtherType is 0x8080';
  336.         if (mac_equals($mac, '09:00:02:04:00:02')) $app = 'Vitalink bridge management, EtherType is 0x8080';
  337.         if (mac_equals($mac, '09:00:4C:00:00:0F')) $app = 'BICC Remote bridge adaptive routing (e.g. to Retix), EtherType is 0x0802';
  338.         if (mac_equals($mac, '09:00:4E:00:00:02')) $app = 'Novell IPX, EtherType is 0x8137';
  339.         if (mac_equals($mac, '09:00:6A:00:01:00')) $app = 'TOP NetBIOS';
  340.         if (mac_equals($mac, '09:00:7C:01:00:01')) $app = 'Vitalink DLS Multicast';
  341.         if (mac_equals($mac, '09:00:7C:01:00:03')) $app = 'Vitalink DLS Inlink';
  342.         if (mac_equals($mac, '09:00:7C:01:00:04')) $app = 'Vitalink DLS and non DLS Multicast';
  343.         if (mac_equals($mac, '09:00:7C:02:00:05')) $app = 'Vitalink diagnostics, EtherType is 0x8080';
  344.         if (mac_equals($mac, '09:00:7C:05:00:01')) $app = 'Vitalink gateway, EtherType is 0x8080';
  345.         if (mac_equals($mac, '09:00:7C:05:00:02')) $app = 'Vitalink Network Validation Message';
  346.         if (mac_equals($mac, '09:00:09:00:00:01')) $app = 'HP Probe, EtherType is 0x8005 or 0x0802';
  347.         if (mac_equals($mac, '09:00:09:00:00:04')) $app = 'HP DTC, EtherType is 0x8005';
  348.         if (mac_equals($mac, '09:00:26:01:00:01')) $app = 'Vitalink TransLAN bridge management, EtherType is 0x8038';
  349.         if (mac_equals($mac, '09:00:39:00:70:00')) $app = 'Spider Systems Bridge';
  350.         if (mac_between($mac, '09:00:56:00:00:00', '09:00:56:FE:FF:FF')) $app = 'Stanford reserved';
  351.         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';
  352.         if (mac_equals($mac, '09:00:77:00:00:00')) $app = 'Retix Bridge Local Management System, EtherType is 0x0802';
  353.         if (mac_equals($mac, '09:00:77:00:00:01')) $app = 'Retix spanning tree bridges, EtherType is 0x0802';
  354.         if (mac_equals($mac, '09:00:77:00:00:02')) $app = 'Retix Bridge Adaptive routing, EtherType is 0x0802';
  355.         if (mac_equals($mac, '09:00:87:80:FF:FF')) $app = 'Xyplex Terminal Servers, EtherType is 0x0889';
  356.         if (mac_equals($mac, '09:00:87:90:FF:FF')) $app = 'Xyplex Terminal Servers, EtherType is 0x0889';
  357.         if (mac_between($mac, '44:38:39:FF:00:00', '44:38:39:FF:FF:FF')) $app = 'Multi-Chassis Link Aggregation (Cumulus Linux)';
  358.         if (mac_equals($mac, 'FF:FF:00:40:00:01')) $app = 'LANtastic, EtherType is 0x81D6';
  359.         if (mac_equals($mac, 'FF:FF:00:60:00:04')) $app = 'LANtastic, EtherType is 0x81D6';
  360.         if (mac_equals($mac, 'FF:FF:01:E0:00:04')) $app = 'LANtastic';
  361.  
  362.         // === FAQ "The "CF" series MAC addresses" ===
  363.         // https://www.iana.org/assignments/ppp-numbers/ppp-numbers.xhtml
  364.         // https://tools.ietf.org/html/rfc2153
  365.         // https://tools.ietf.org/html/rfc7042#section-2.3.2
  366.         if (mac_between($mac, 'CF:00:00:00:00:00', 'CF:00:00:FF:FF:FF')) $app = 'Reserved';
  367.         if (mac_equals($mac, 'CF:00:00:00:00:00')) $app = 'Used for Ethernet loopback tests';
  368.  
  369.         // === FAQ "How to recognise a Broadcast MAC address application?" ===
  370.         if (mac_equals($mac, 'FF:FF:FF:FF:FF:FF')) echo sprintf("%-32s %s\n", "Special use:", "Broadcast messaging");
  371.  
  372.         // === FAQ "How to recognise a Virtual Router ID by MAC address?" ===
  373.         // https://tools.ietf.org/html/rfc7042#section-5.1
  374.         // https://tools.ietf.org/html/rfc5798
  375.         if (mac_between($mac, '00:00:5E:00:01:00', '00:00:5E:00:01:FF')) $app = 'IPv4 Virtual Router Redundancy Protocol  (VRRP)';
  376.         if (mac_between($mac, '00:00:5E:00:02:00', '00:00:5E:00:02:FF')) $app = 'IPv6 Virtual Router Redundancy Protocol';
  377.  
  378.         // === FAQ "How to recognise an IP frame by MAC address?" ===
  379.         // https://tools.ietf.org/html/rfc1060
  380.         // https://en.wikipedia.org/wiki/Multicast_address#cite_note-15
  381.         // https://tools.ietf.org/html/rfc2464
  382.         // https://www.iana.org/go/rfc1112
  383.         // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
  384.         if (mac_between($mac, '01:00:5E:00:00:00', '01:00:5E:7F:FF:FF')) $app = 'IPv4 Multicast (EtherType is 0x0800)';
  385.         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.
  386.         if (mac_between($mac, '00:00:5E:00:52:13', '00:00:5E:00:52:13')) $app = 'Proxy Mobile IPv6';
  387.         if (mac_between($mac, '00:00:5E:FE:C0:00:02:00', '00:00:5E:FE:C0:00:02:FF')) $app = 'IPv4 derived documentation';
  388.         if (mac_between($mac, '00:00:5E:FE:C6:33:64:00', '00:00:5E:FE:C6:33:64:FF')) $app = 'IPv4 derived documentation';
  389.         if (mac_between($mac, '00:00:5E:FE:CB:00:71:00', '00:00:5E:FE:CB:00:71:FF')) $app = 'IPv4 derived documentation';
  390.         if (mac_equals($mac, '00:00:5E:FE:EA:C0:00:02')) $app = 'IPv4 multicast derived documentation';
  391.         if (mac_equals($mac, '00:00:5E:FE:EA:C6:33:64')) $app = 'IPv4 multicast derived documentation';
  392.         if (mac_equals($mac, '00:00:5E:FE:EA:CB:00:71')) $app = 'IPv4 multicast derived documentation';
  393.         if (mac_between($mac, '01:00:5E:FE:C0:00:02:00', '01:00:5E:FE:C0:00:02:FF')) $app = 'IPv4 derived documentation';
  394.         if (mac_between($mac, '01:00:5E:FE:C6:33:64:00', '01:00:5E:FE:C6:33:64:FF')) $app = 'IPv4 derived documentation';
  395.         if (mac_between($mac, '01:00:5E:FE:CB:00:71:00', '01:00:5E:FE:CB:00:71:FF')) $app = 'IPv4 derived documentation';
  396.         if (mac_equals($mac, '01:00:5E:FE:EA:C0:00:02')) $app = 'IPv4 multicast derived documentation';
  397.         if (mac_equals($mac, '01:00:5E:FE:EA:C6:33:64')) $app = 'IPv4 multicast derived documentation';
  398.         if (mac_equals($mac, '01:00:5E:FE:EA:CB:00:71')) $app = 'IPv4 multicast derived documentation';
  399.         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';
  400.         if (mac_between($mac, '02:00:5E:FE:00:00:00:00', '02:00:5E:FE:FF:FF:FF:FF')) $app = 'IPv4 Addr Holders';
  401.         if (mac_equals($mac, '03:00:00:20:00:00')) $app = 'IP multicast address';
  402.         if (mac_equals($mac, 'C0:00:00:04:00:00')) $app = 'IP multicast address';
  403.         if (mac_between($mac, '03:00:5E:FE:00:00:00:00', '03:00:5E:FE:FF:FF:FF:FF')) $app = 'IPv4 Addr Holders';
  404.  
  405.         // === FAQ "How to recognise a MPLS multicast frame by MAC address?" ===
  406.         // http://www.iana.org/go/rfc5332
  407.         // http://www.iana.org/go/rfc7213
  408.         if (mac_between($mac, '01:00:5E:80:00:00', '01:00:5E:8F:FF:FF')) $app = 'MPLS multicast (EtherType is 0x8847 or 0x8848)';
  409.         if (mac_equals($mac, '01:00:5E:90:00:00')) $app = 'MPLS-TP p2p';
  410.  
  411.         // === FAQ "How to recognise a Bidirectional Forwarding Detection (BFD) on Link Aggregation Group (LAG) interfaces by MAC address?" ===
  412.         // http://www.iana.org/go/rfc7130
  413.         if (mac_equals($mac, '01:00:5E:90:00:01')) $app = 'Bidirectional Forwarding Detection (BFD) on Link Aggregation Group (LAG) interfaces';
  414.  
  415.         // === FAQ "How to recognise Token Ring specific functions by MAC address?" ===
  416.         // https://tools.ietf.org/html/rfc1060
  417.         // https://tools.ietf.org/html/rfc1469
  418.         // https://standards.ieee.org/products-services/regauth/grpmac/public.html
  419.         // https://tools.ietf.org/html/rfc2470
  420.         // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
  421.         if (mac_equals($mac, '03:00:00:00:00:01')) $app = 'NetBIOS (Token Ring)';
  422.         if (mac_equals($mac, '03:00:00:00:00:02')) $app = 'Locate - Directory Server (Token Ring)';
  423.         if (mac_equals($mac, '03:00:00:00:00:04')) $app = 'Synchronous Bandwidth Manager (Token Ring)';
  424.         if (mac_equals($mac, '03:00:00:00:00:08')) $app = 'Configuration Report Server (Token Ring)';
  425.         if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'Ring Error Monitor (Token Ring)';
  426.         if (mac_equals($mac, '03:00:00:00:00:20')) $app = 'Network Server Heartbeat (Token Ring)';
  427.         if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'Ring Parameter Monitor (Token Ring)';
  428.         if (mac_equals($mac, '03:00:00:00:00:80')) $app = 'Active Monitor (Token Ring)';
  429.         if (mac_equals($mac, '03:00:00:00:04:00')) $app = 'LAN Manager (Token Ring)';
  430.         if (mac_equals($mac, '03:00:00:00:08:00')) $app = 'Ring Wiring Concentrator (Token Ring)';
  431.         if (mac_equals($mac, '03:00:00:00:10:00')) $app = 'LAN Gateway (Token Ring)';
  432.         if (mac_equals($mac, '03:00:00:00:20:00')) $app = 'Ring Authorization Server (Token Ring)';
  433.         if (mac_equals($mac, '03:00:00:00:40:00')) $app = 'IMPL Server (Token Ring)';
  434.         if (mac_equals($mac, '03:00:00:00:80:00')) $app = 'Bridge (Token Ring)';
  435.         if (mac_equals($mac, '03:00:00:20:00:00')) $app = 'Single Token-Ring functional address';
  436.         if (mac_equals($mac, '03:00:00:00:00:08')) $app = 'Configuration Report Server (CRS) MAC Group address';
  437.         if (mac_equals($mac, '03:00:00:00:00:10')) $app = 'Ring Error Monitor (REM) MAC Group address';
  438.         if (mac_equals($mac, '03:00:00:00:00:40')) $app = 'Ring Parameter Server (RPS) MAC group address';
  439.         if (mac_equals($mac, '03:00:00:00:01:00')) $app = 'All Intermediate System Network Entities address';
  440.         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';
  441.         if (mac_equals($mac, '03:00:00:00:04:00')) $app = 'Generic address for all Manager Stations';
  442.         if (mac_equals($mac, '03:00:00:00:08:00')) $app = 'All CONs SNARES address';
  443.         if (mac_equals($mac, '03:00:00:00:10:00')) $app = 'All CONs End System address';
  444.         if (mac_equals($mac, '03:00:00:00:20:00')) $app = 'Loadable Device Generic address';
  445.         if (mac_equals($mac, '03:00:00:00:40:00')) $app = 'Load Server Generic address';
  446.         if (mac_equals($mac, '03:00:00:40:00:00')) $app = 'Generic address for all Agent Stations';
  447.         if (mac_equals($mac, 'C0:00:00:04:00:00')) $app = 'Single Token-Ring functional address';
  448.         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';
  449.         if (mac_equals($mac, '03:00:40:00:00:00')) $app = 'IPv6 multicast over Token Ring: all-Routers addresses (FF0X::2)';
  450.         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';
  451.         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';
  452.         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';
  453.         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';
  454.         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';
  455.         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';
  456.         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';
  457.         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';
  458.  
  459.         // === FAQ "How to recognise an AppleTalk protocols by MAC address?" ===
  460.         // https://tools.ietf.org/html/rfc1060
  461.         // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
  462.         if (mac_between($mac, '09:00:07:00:00:00', '09:00:07:00:00:FC')) $app = 'AppleTalk zone multicast addresses (EtherType is 0x0802)';
  463.         if (mac_equals($mac, '09:00:07:FF:FF:FF')) $app = 'AppleTalk broadcast address (EtherType is 0x0802)';
  464.  
  465.         // === FAQ "How to recognise a TRILL protocols by MAC address?" ===
  466.         // http://www.iana.org/go/rfc7455
  467.         // https://tools.ietf.org/html/draft-ietf-trill-oam-framework-04
  468.         // https://standards.ieee.org/products-services/regauth/grpmac/public.html
  469.         // https://tools.ietf.org/html/rfc7455#appendix-C
  470.         if (mac_between($mac, '00:00:5E:90:01:00', '00:00:5E:90:01:00')) $app = 'TRILL OAM';
  471.         if (mac_equals($mac, '01:00:5E:90:01:00')) $app = 'TRILL OAM';
  472.         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';
  473.  
  474.         // === FAQ "How to recognise an IEEE 802.1X MAC address application?" ===
  475.         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';
  476.         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';
  477.         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';
  478.         if (mac_equals($mac, '01:1B:19:00:00:00')) $app = 'General group address - An 802.1Q VLAN Bridge would forward the frame unchanged.';
  479.         if (mac_equals($mac, '01:1B:19:00:00:00')) $app = 'Precision Time Protocol (PTP) version 2 over Ethernet, EtherType is 0x88F7';
  480.         if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Bridge Group address Nearest Customer Bridge group address';
  481.         if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Spanning Tree Protocol (for bridges) IEEE 802.1D, EtherType is 0x0802';
  482.         if (mac_equals($mac, '01:80:C2:00:00:00')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
  483.         if (mac_between($mac, '01:80:C2:00:00:00', '01:80:C2:00:00:0F')) $app = 'The initial bridging/link protocols block';
  484.         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';
  485.         if (mac_between($mac, '01:80:C2:00:00:00', '01:80:C2:00:00:0F')) $app = 'IEEE Pause, 802.3x';
  486.         if (mac_equals($mac, '01:80:C2:00:00:0A')) $app = 'Reserved for future standardization';
  487.         if (mac_equals($mac, '01:80:C2:00:00:0B')) $app = 'EDE-SS PEP Address';
  488.         if (mac_equals($mac, '01:80:C2:00:00:0C')) $app = 'Reserved for future standardization';
  489.         if (mac_equals($mac, '01:80:C2:00:00:0D')) $app = 'Provider Bridge MVRP address';
  490.         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';
  491.         if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Nearest Bridge group address';
  492.         if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
  493.         if (mac_equals($mac, '01:80:C2:00:00:0E')) $app = 'Precision Time Protocol (PTP) version 2 over Ethernet, EtherType is 0x88F7';
  494.         if (mac_equals($mac, '01:80:C2:00:00:01')) $app = 'IEEE MAC-specific Control Protocols group address';
  495.         if (mac_equals($mac, '01:80:C2:00:00:01')) $app = 'Ethernet flow control (Pause frame) IEEE 802.3x, EtherType is 0x8808';
  496.         if (mac_equals($mac, '01:80:C2:00:00:1A')) $app = 'Generic Address for All Agent Stations';
  497.         if (mac_equals($mac, '01:80:C2:00:00:1B')) $app = 'All Multicast Capable End Systems address';
  498.         if (mac_equals($mac, '01:80:C2:00:00:1C')) $app = 'All Multicast Announcements address';
  499.         if (mac_equals($mac, '01:80:C2:00:00:1D')) $app = 'All Multicast Capable Intermediate Systems address';
  500.         if (mac_equals($mac, '01:80:C2:00:00:1E')) $app = 'All DTR Concentrators MAC group address';
  501.         if (mac_equals($mac, '01:80:C2:00:00:1F')) $app = 'EDE-CC PEP Address';
  502.         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';
  503.         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';
  504.         if (mac_equals($mac, '01:80:C2:00:00:03')) $app = 'Nearest non-TPMR Bridge group address IEEE Std 802.1X PAE address';
  505.         if (mac_equals($mac, '01:80:C2:00:00:03')) $app = 'Link Layer Discovery Protocol, EtherType is 0x88CC';
  506.         if (mac_equals($mac, '01:80:C2:00:00:04')) $app = 'IEEE MAC-specific Control Protocols group address';
  507.         if (mac_equals($mac, '01:80:C2:00:00:05')) $app = 'Reserved for future standardization';
  508.         if (mac_equals($mac, '01:80:C2:00:00:06')) $app = 'Reserved for future standardization';
  509.         if (mac_equals($mac, '01:80:C2:00:00:07')) $app = 'MEF Forum ELMI protocol group address';
  510.         if (mac_equals($mac, '01:80:C2:00:00:08')) $app = 'Provider Bridge group address';
  511.         if (mac_equals($mac, '01:80:C2:00:00:08')) $app = 'Spanning Tree Protocol (for provider bridges) IEEE 802.1ad, EtherType is 0x0802';
  512.         if (mac_equals($mac, '01:80:C2:00:00:09')) $app = 'Reserved for future standardization';
  513.         if (mac_equals($mac, '01:80:C2:00:00:10')) $app = 'All LANs Bridge Management group address (deprecated)';
  514.         if (mac_equals($mac, '01:80:C2:00:00:10')) $app = 'Bridge Management, EtherType is 0x0802';
  515.         if (mac_equals($mac, '01:80:C2:00:00:11')) $app = 'Load Server generic address';
  516.         if (mac_equals($mac, '01:80:C2:00:00:11')) $app = 'Load Server, EtherType is 0x0802';
  517.         if (mac_equals($mac, '01:80:C2:00:00:12')) $app = 'Loadable Device generic address';
  518.         if (mac_equals($mac, '01:80:C2:00:00:12')) $app = 'Loadable Device, EtherType is 0x0802';
  519.         if (mac_equals($mac, '01:80:C2:00:00:13')) $app = 'Transmission of IEEE 1905.1 control packets';
  520.         if (mac_equals($mac, '01:80:C2:00:00:14')) $app = 'All Level 1 Intermediate Systems address';
  521.         if (mac_equals($mac, '01:80:C2:00:00:14')) $app = 'OSI Route level 1 (within area), EtherType is 0x0802';
  522.         if (mac_equals($mac, '01:80:C2:00:00:15')) $app = 'All Level 2 Intermediate Systems address';
  523.         if (mac_equals($mac, '01:80:C2:00:00:15')) $app = 'OSI Route level 2 (between area), EtherType is 0x0802';
  524.         if (mac_equals($mac, '01:80:C2:00:00:16')) $app = 'All CONS End Systems address';
  525.         if (mac_equals($mac, '01:80:C2:00:00:17')) $app = 'All CONS SNARES address';
  526.         if (mac_equals($mac, '01:80:C2:00:00:18')) $app = 'Generic address for All Manager Stations';
  527.         if (mac_equals($mac, '01:80:C2:00:00:19')) $app = 'Groupcast with retries (GCR) MAC group address';
  528.         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';
  529.         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';
  530.         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';
  531.         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';
  532.         if (mac_between($mac, '01:80:C2:00:00:50', '01:80:C2:00:00:FF')) $app = 'Unassigned standard group MAC address';
  533.         if (mac_equals($mac, '01:80:C2:00:01:00')) $app = 'Ring Management Directed Beacon multicast address';
  534.         if (mac_equals($mac, '01:80:C2:00:01:00')) $app = 'FDDI RMT Directed Beacon, EtherType is 0x0802';
  535.         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';
  536.         if (mac_equals($mac, '01:80:C2:00:01:10')) $app = 'Status Report Frame Status Report Protocol multicast address';
  537.         if (mac_equals($mac, '01:80:C2:00:01:10')) $app = 'FDDI status report frame, EtherType is 0x0802';
  538.         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';
  539.         if (mac_equals($mac, '01:80:C2:00:01:20')) $app = 'All FDDI Concentrator MACs';
  540.         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';
  541.         if (mac_equals($mac, '01:80:C2:00:01:30')) $app = 'Synchronous Bandwidth Allocation address';
  542.         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';
  543.         if (mac_between($mac, '01:80:C2:00:02:00', '01:80:C2:00:02:FF')) $app = 'Assigned to ETSI for future use';
  544.         if (mac_between($mac, '01:80:C2:00:03:00', '01:80:C2:FF-FF-FF')) $app = 'Unassigned standard group MAC address';
  545.         if (mac_equals($mac, '09:00:4C:00:00:00')) $app = 'BICC 802.1 management, EtherType is 0x0802';
  546.         if (mac_equals($mac, '09:00:4C:00:00:0C')) $app = 'BICC Remote bridge STA 802.1(D) Rev8, EtherType is 0x0802';
  547.         if (mac_equals($mac, '09:00:4C:00:00:02')) $app = 'BICC 802.1 management, EtherType is 0x0802';
  548.         if (mac_equals($mac, '09:00:4C:00:00:06')) $app = 'BICC Local bridge STA 802.1(D) Rev6, EtherType is 0x0802';
  549.         if (mac_between($mac, '33:33:00:00:00:00', '33:33:FF:FF:FF:FF')) $app = 'IPv6 multicast, EtherType is 0x86DD';
  550.  
  551.         // === FAQ "How to recognise an ISO 9542 ES-IS protocol's MAC address application?" ===
  552.         // https://standards.ieee.org/products-services/regauth/grpmac/public.html
  553.         if (mac_equals($mac, '09:00:2B:00:00:04')) $app = 'All End System Network Entities address';
  554.         if (mac_equals($mac, '09:00:2B:00:00:05')) $app = 'All Intermediate System Network Entities address';
  555.  
  556.         // === FAQ "How to recognise an IANA MAC address application?" ===
  557.         // https://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml
  558.         // http://www.iana.org/go/rfc7042
  559.         // https://tools.ietf.org/html/rfc1060
  560.         if (mac_between($mac, '00:00:5E:00-52:14', '00:00:5E:00:52:FF')) $app = 'Unassigned (small allocations)';
  561.         if (mac_between($mac, '00:00:5E:00:00:00', '00:00:5E:00:00:FF')) $app = 'Reserved and require IESG Ratification for assignment';
  562.         if (mac_between($mac, '00:00:5E:00:03:00', '00:00:5E:00:51:FF')) $app = 'Unassigned';
  563.         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.';
  564.         if (mac_between($mac, '00:00:5E:00:52:00', '00:00:5E:00:52:00')) $app = 'PacketPWEthA';
  565.         if (mac_between($mac, '00:00:5E:00:52:01', '00:00:5E:00:52:01')) $app = 'PacketPWEthB';
  566.         if (mac_between($mac, '00:00:5E:00:52:02', '00:00:5E:00:52:12')) $app = 'Unassigned (small allocations)';
  567.         if (mac_between($mac, '00:00:5E:00:53:00', '00:00:5E:00:53:FF')) $app = 'Assigned for use in documentation';
  568.         if (mac_between($mac, '00:00:5E:00:54:00', '00:00:5E:90:00:FF')) $app = 'Unassigned';
  569.         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)';
  570.         if (mac_between($mac, '00:00:5E:EF:10:00:00:00', '00:00:5E:EF:10:00:00:FF')) $app = 'General documentation';
  571.         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';
  572.         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.)
  573.         if (mac_between($mac, '01:00:5E:80:00:00', '01:00:5E:FF:FF:FF')) $app = 'DoD Internet';
  574.         if (mac_equals($mac, '01:00:5E:90:00:02')) $app = 'AllL1MI-ISs';
  575.         if (mac_equals($mac, '01:00:5E:90:00:03')) $app = 'AllL2MI-ISs';
  576.         if (mac_between($mac, '01:00:5E:90:00:04', '01:00:5E:90:00:FF')) $app = 'Unassigned (small allocations)';
  577.         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)';
  578.         if (mac_between($mac, '01:00:5E:90:02:00', '01:00:5E:90:0F:FF')) $app = 'Unassigned';
  579.         if (mac_between($mac, '01:00:5E:90:02:00', '00:00:5E:FF:FF:FF')) $app = 'Unassigned';
  580.         if (mac_between($mac, '01:00:5E:90:10:00', '01:00:5E:90:10:FF')) $app = 'Documentation';
  581.         if (mac_between($mac, '01:00:5E:90:11:00', '01:00:5E:FF:FF:FF')) $app = 'Unassigned';
  582.         if (mac_between($mac, '01:00:5E:EF:10:00:00:00', '01:00:5E:EF:10:00:00:FF')) $app = 'General documentation';
  583.         if (mac_between($mac, '02:00:5E:00:00:00:00:00', '02:00:5E:0F:FF:FF:FF:FF')) $app = 'Reserved';
  584.         if (mac_between($mac, '02:00:5E:10:00:00:00:00', '02:00:5E:10:00:00:00:FF')) $app = 'Documentation';
  585.         if (mac_between($mac, '02:00:5E:10:00:00:01:00', '02:00:5E:EF:FF:FF:FF:FF')) $app = 'Unassigned';
  586.         if (mac_between($mac, '02:00:5E:F0:00:00:00:00', '02:00:5E:FD:FF:FF:FF:FF')) $app = 'Reserved';
  587.         if (mac_between($mac, '02:00:5E:FE:00:00:00:00', '02:00:5E:FE:FF:FF:FF:FF')) $app = 'IPv4 Addr Holders';
  588.         if (mac_between($mac, '02:00:5E:FF:00:00:00:00', '02:00:5E:FF:FD:FF:FF:FF')) $app = 'Reserved';
  589.         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';
  590.         if (mac_between($mac, '02:00:5E:FF:FF:00:00:00', '02:00:5E:FF:FF:FF:FF:FF')) $app = 'Reserved';
  591.         if (mac_between($mac, '03:00:5E:00:00:00:00:00', '03:00:5E:0F:FF:FF:FF:FF')) $app = 'Reserved';
  592.         if (mac_between($mac, '03:00:5E:10:00:00:00:00', '03:00:5E:10:00:00:00:FF')) $app = 'Documentation';
  593.         if (mac_between($mac, '03:00:5E:10:00:00:01:00', '03:00:5E:EF:FF:FF:FF:FF')) $app = 'Unassigned';
  594.         if (mac_between($mac, '03:00:5E:F0:00:00:00:00', '03:00:5E:FD:FF:FF:FF:FF')) $app = 'Reserved';
  595.         if (mac_between($mac, '03:00:5E:FF:00:00:00:00', '03:00:5E:FF:FD:FF:FF:FF')) $app = 'Reserved';
  596.         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';
  597.         if (mac_between($mac, '03:00:5E:FF:FF:00:00:00', '03:00:5E:FF:FF:FF:FF:FF')) $app = 'Reserved';
  598.  
  599.         // === FAQ "How to recognise a Cisco's MAC address application?" ===
  600.         // https://www.cisco.com/c/en/us/support/docs/switches/catalyst-4500-series-switches/13414-103.html
  601.         // https://tools.ietf.org/html/rfc1060
  602.         // https://en.wikipedia.org/wiki/Multicast_address#cite_note-15
  603.         // http://www.cavebear.com/archive/cavebear/Ethernet/Ethernet.txt
  604.         if (mac_equals($mac, '01:00:0C:00:00:00')) $app = 'Inter Switch Link (ISL)';
  605.         if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'CDP (Cisco Discovery Protocol), VTP (VLAN Trunking Protocol), EtherType is 0x0802';
  606.         if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Port Aggregation Protocol (PAgP), SNAP HDLC Protocol Type is 0x0104';
  607.         if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Unidirectional Link Detection (UDLD), SNAP HDLC Protocol Type is 0x0111';
  608.         if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'Dynamic Trunking (DTP), SNAP HDLC Protocol Type is 0x2004';
  609.         if (mac_equals($mac, '01:00:0C:CC:CC:CC')) $app = 'VLAN Trunking (VTP), SNAP HDLC Protocol Type is 0x2003';
  610.         if (mac_equals($mac, '01:00:0C:CC:CC:CD')) $app = 'Cisco Shared Spanning Tree Protocol address, EtherType is 0x0802';
  611.         if (mac_equals($mac, '01:00:0C:CC:CC:CD')) $app = 'Spanning Tree PVSTP+, SNAP HDLC Protocol Type is 0x010B';
  612.         if (mac_equals($mac, '01:00:0C:CD:CD:CD')) $app = 'STP Uplink Fast, SNAP HDLC Protocol Type is 0x200A';
  613.         if (mac_equals($mac, '01:00:0C:CD:CD:CE')) $app = 'VLAN Bridge, SNAP HDLC Protocol Type is 0x010C';
  614.         if (mac_equals($mac, '01:00:0C:DD:DD:DD')) $app = 'CGMP (Cisco Group Management Protocol)';
  615.  
  616.         // === FAQ "How to recognise an ITU-T's MAC address application?" ===
  617.         // https://www.itu.int/en/ITU-T/studygroups/2017-2020/15/Documents/IEEE-assigned_OUIs-30-06-2017.docx
  618.         if (mac_between($mac, '01:19:A7:00:00:00', '01:19:A7:00:00:FF')) $app = 'R-APS per G.8032';
  619.         if (mac_between($mac, '01:19:A7:52:76:90', '01:19:A7:52:76:9F')) $app = 'Multicast per G.9961';
  620.  
  621.         // === FAQ "How to recognise Digital Equipment Corporation's MAC address application?" ===
  622.         if (mac_equals($mac, '09:00:2B:00:00:00')) $app = 'DEC MUMPS, EtherType is 0x6009';
  623.         if (mac_equals($mac, '09:00:2B:00:00:0F')) $app = 'DEC Local Area Transport (LAT), EtherType is 0x6004';
  624.         if (mac_equals($mac, '09:00:2B:00:00:01')) $app = 'DEC DSM/DDP, EtherType is 0x8039';
  625.         if (mac_between($mac, '09:00:2B:00:00:10', '09:00:2B:00:00:1F')) $app = 'DEC Experimental';
  626.         if (mac_equals($mac, '09:00:2B:00:00:02')) $app = 'DEC VAXELN, EtherType is 0x803B';
  627.         if (mac_equals($mac, '09:00:2B:00:00:03')) $app = 'DEC Lanbridge Traffic Monitor (LTM), EtherType is 0x8038';
  628.         if (mac_equals($mac, '09:00:2B:00:00:04')) $app = 'DEC MAP End System';
  629.         if (mac_equals($mac, '09:00:2B:00:00:05')) $app = 'DEC MAP Intermediate System';
  630.         if (mac_equals($mac, '09:00:2B:00:00:06')) $app = 'DEC CSMA/CD Encryption, EtherType is 0x803D';
  631.         if (mac_equals($mac, '09:00:2B:00:00:07')) $app = 'DEC NetBios Emulator, EtherType is 0x8040';
  632.         if (mac_equals($mac, '09:00:2B:01:00:00')) $app = 'DEC LanBridge, EtherType is 0x8038';
  633.         if (mac_equals($mac, '09:00:2B:01:00:01')) $app = 'DEC LanBridge, EtherType is 0x8038';
  634.         if (mac_equals($mac, '09:00:2B:02:00:00')) $app = 'DEC DNA Level 2 Routing';
  635.         if (mac_equals($mac, '09:00:2B:02:01:00')) $app = 'DEC DNA Naming Service Advertisement, EtherType is 0x803C';
  636.         if (mac_equals($mac, '09:00:2B:02:01:01')) $app = 'DEC DNA Naming Service Solicitation, EtherType is 0x803C';
  637.         if (mac_equals($mac, '09:00:2B:02:01:02')) $app = 'DEC Distributed Time Service, EtherType is 0x803E';
  638.         if (mac_equals($mac, '09:00:2B:02:01:09')) $app = 'DEC Availability Manager for Distributed Systems DECamds, EtherType is 0x8048';
  639.         if (mac_between($mac, '09:00:2B:03:00:00', '09:00:2B:03:FF:FF')) $app = 'DEC default filtering by bridges';
  640.         if (mac_equals($mac, '09:00:2B:04:00:00')) $app = 'DEC Local Area System Transport (LAST), EtherType is 0x8041';
  641.         if (mac_equals($mac, '09:00:2B:23:00:00')) $app = 'DEC Argonaut Console, EtherType is 0x803A';
  642.         if (mac_equals($mac, 'AB:00:00:01:00:00')) $app = 'DEC Maintenance Operation Protocol (MOP) Dump/Load Assistance, EtherType is 0x6001';
  643.         if (mac_equals($mac, 'AB:00:00:02:00:00')) $app = 'DEC Maintenance Operation Protocol (MOP), EtherType is 0x6002';
  644.         if (mac_equals($mac, 'AB:00:00:03:00:00')) $app = 'DECNET Phase IV end node, EtherType is 0x6003';
  645.         if (mac_equals($mac, 'AB:00:00:04:00:00')) $app = 'DECNET Phase IV Router, EtherType is 0x6003';
  646.         if (mac_between($mac, 'AB:00:00:05:00:00', 'AB:00:03:FF:FF:FF')) $app = 'Reserved DEC';
  647.         if (mac_equals($mac, 'AB:00:03:00:00:00')) $app = 'DEC Local Area Transport (LAT) - old, EtherType is 0x6004';
  648.         if (mac_between($mac, 'AB:00:04:00:00:00', 'AB:00:04:00:FF:FF')) $app = 'Reserved DEC customer private use';
  649.         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';
  650.  
  651.         if ($app) {
  652.                 echo sprintf("%-32s %s\n", "Special use:", $app);
  653.         }
  654.  
  655. }
  656.  
  657. /**
  658.  * @param string $mac1
  659.  * @param string $mac2
  660.  * @return bool
  661.  */
  662. function mac_equals(string $mac1, string $mac2): bool {
  663.         $mac1test = eui64_to_eui48($mac1);
  664.         if ($mac1test === false) return false;
  665.         $mac2test = eui64_to_eui48($mac2);
  666.         if ($mac2test === false) return false;
  667.  
  668.         if (eui_bits($mac1test) != eui_bits($mac2test)) {
  669.                 $mac1test = eui48_to_eui64($mac1);
  670.                 $mac2test = eui48_to_eui64($mac2);
  671.         }
  672.  
  673.         return mac_canonize($mac1test) == mac_canonize($mac2test);
  674. }
  675.  
  676. /**
  677.  * @param string $mac
  678.  * @param string $low
  679.  * @param string $high
  680.  * @return bool
  681.  */
  682. function mac_between(string $mac, string $low, string $high): bool {
  683.         $mactest = eui64_to_eui48($mac);
  684.         if ($mactest === false) return false;
  685.         $lowtest = eui64_to_eui48($low);
  686.         if ($lowtest === false) return false;
  687.         $hightest = eui64_to_eui48($high);
  688.         if ($hightest === false) return false;
  689.  
  690.         if ((eui_bits($mactest) != eui_bits($lowtest)) || (eui_bits($lowtest) != eui_bits($hightest))) {
  691.                 $mactest = eui48_to_eui64($mac);
  692.                 $lowtest = eui48_to_eui64($low);
  693.                 $hightest = eui48_to_eui64($high);
  694.         }
  695.  
  696.         $mactest = strtoupper(preg_replace('@[^0-9A-F]@', '', $mactest));
  697.         $lowtest = strtoupper(preg_replace('@[^0-9A-F]@', '', $lowtest));
  698.         $hightest = strtoupper(preg_replace('@[^0-9A-F]@', '', $hightest));
  699.  
  700.         $mactest = gmp_init($mactest, 16);
  701.         $lowtest = gmp_init($lowtest, 16);
  702.         $hightest = gmp_init($hightest, 16);
  703.  
  704.         return (gmp_cmp($mactest, $lowtest) >= 0) && (gmp_cmp($mactest, $hightest) <= 0);
  705. }