Subversion Repositories uuid_mac_utils

Compare Revisions

Regard whitespace Rev 17 → Rev 18

/trunk/download-webdata.sh
10,26 → 10,32
fi
 
# 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.
wget http://standards.ieee.org/develop/regauth/iab/iab.txt -O "$DIR"/web-data/iab.txt
wget https://standards-oui.ieee.org/iab/iab.txt -O "$DIR"/web-data/iab.txt
if [ $? -ne 0 ]; then
sleep 300
wget http://standards.ieee.org/develop/regauth/iab/iab.txt -O "$DIR"/web-data/iab.txt
wget https://standards-oui.ieee.org/iab/iab.txt -O "$DIR"/web-data/iab.txt
fi
 
wget http://standards.ieee.org/develop/regauth/oui/oui.txt -O "$DIR"/web-data/oui.txt
wget https://standards-oui.ieee.org/oui/oui.txt -O "$DIR"/web-data/oui.txt
if [ $? -ne 0 ]; then
sleep 300
wget http://standards.ieee.org/develop/regauth/oui/oui.txt -O "$DIR"/web-data/oui.txt
wget https://standards-oui.ieee.org/oui/oui.txt -O "$DIR"/web-data/oui.txt
fi
 
wget http://standards.ieee.org/develop/regauth/oui28/mam.txt -O "$DIR"/web-data/mam.txt
wget https://standards-oui.ieee.org/oui28/mam.txt -O "$DIR"/web-data/mam.txt
if [ $? -ne 0 ]; then
sleep 300
wget http://standards.ieee.org/develop/regauth/oui28/mam.txt -O "$DIR"/web-data/mam.txt
wget https://standards-oui.ieee.org/oui28/mam.txt -O "$DIR"/web-data/mam.txt
fi
 
wget http://standards.ieee.org/develop/regauth/oui36/oui36.txt -O "$DIR"/web-data/oui36.txt
wget https://standards-oui.ieee.org/oui36/oui36.txt -O "$DIR"/web-data/oui36.txt
if [ $? -ne 0 ]; then
sleep 300
wget http://standards.ieee.org/develop/regauth/oui36/oui36.txt -O "$DIR"/web-data/oui36.txt
wget https://standards-oui.ieee.org/oui36/oui36.txt -O "$DIR"/web-data/oui36.txt
fi
 
wget https://standards-oui.ieee.org/cid/cid.txt -O "$DIR"/web-data/cid.txt
if [ $? -ne 0 ]; then
sleep 300
wget https://standards-oui.ieee.org/cid/cid.txt -O "$DIR"/web-data/cid.txt
fi
/trunk/includes/mac_utils.inc.php
18,10 → 18,15
* limitations under the License.
*/
 
// Very good resources for information about OUI, EUI, MAC, ...
// - https://mac-address.alldatafeeds.com/faq#how-to-recognise-mac-address-application
// - https://standards.ieee.org/wp-content/uploads/import/documents/tutorials/eui.pdf
// - https://en.m.wikipedia.org/wiki/Organizationally_unique_identifier
 
const IEEE_MAC_REGISTRY = __DIR__ . '/../web-data';
 
/**
* Checks if a MAC, EUI, or IPv6-LinkLocal address is valid
* Checks if a MAC, EUI, ELI, or IPv6-LinkLocal address is valid
* @param string $mac MAC, EUI, or IPv6-LinkLocal Address
* @return bool True if it is valid
*/
40,7 → 45,7
}
 
/**
* Returns the amount of bits of a MAC or EUI
* Returns the amount of bits of a MAC, EUI, or ELI
* @param string $mac
* @return false|int
*/
51,8 → 56,8
}
 
/**
* Canonizes a MAC, EUI, or IPv6-LinkLocal address
* @param string $mac MAC, EUI, or IPv6-LinkLocal Address
* Canonizes a MAC, EUI, ELI, or IPv6-LinkLocal address
* @param string $mac MAC, EUI, ELI, or IPv6-LinkLocal Address
* @param string $delimiter Desired delimiter for inserting between each octet
* @return string|false The canonized address (Note: IPv6-Linklocal becomes EUI-64)
*/
133,6 → 138,7
if (!mac_valid($eui64)) return false;
$eui64 = mac_canonize($eui64, '');
if (eui_bits($eui64) == 48) return mac_canonize($eui64);
if ($eui64[1] == 'A') return false; // do not allow ELI-64
 
if (substr($eui64, 6, 4) == 'FFFF') {
// EUI-64 to MAC-48
162,6 → 168,7
if (!mac_valid($mac48)) return false;
$mac48 = mac_canonize($mac48, '');
if (eui_bits($mac48) == 64) return mac_canonize($mac48);
if ($mac48[1] == 'A') return false; // do not allow ELI-48
 
$eui64 = substr($mac48, 0, 6).'FFFF'.substr($mac48, 6, 6);
return mac_canonize($eui64);
178,6 → 185,7
if (!mac_valid($eui48)) return false;
$eui48 = mac_canonize($eui48, '');
if (eui_bits($eui48) == 64) return mac_canonize($eui48);
if ($eui48[1] == 'A') return false; // do not allow ELI-48
 
$eui64 = substr($eui48, 0, 6).'FFFE'.substr($eui48, 6, 6);
return mac_canonize($eui64);
194,6 → 202,7
if (!mac_valid($eui48)) return false;
$eui48 = mac_canonize($eui48, '');
if (eui_bits($eui48) == 64) return mac_canonize($eui48);
if ($eui48[1] == 'A') return false; // do not allow ELI-48
 
$eui64 = substr($eui48, 0, 6).'FFFE'.substr($eui48, 6, 6);
 
248,14 → 257,12
}
 
/**
* Prints information about an IPv6-LinkLocal address, MAC, or EUI.
* @param string $mac IPv6-LinkLocal address, MAC, or EUI
* Prints information about an IPv6-LinkLocal address, MAC, EUI, or ELI.
* @param string $mac IPv6-LinkLocal address, MAC, EUI, or ELI
* @return void
* @throws Exception
*/
function decode_mac(string $mac) {
// Amazing website about MAC addresses: https://mac-address.alldatafeeds.com/faq#how-to-recognise-mac-address-application
 
echo sprintf("%-32s %s\n", "Input:", $mac);
 
// Format MAC for machine readability
262,6 → 269,12
$mac = mac_canonize($mac, '');
 
$type = '';
if ($mac[1] == 'A') {
// An ELI is based on a CID-24
// A CID has ZYXM bits set to 1010 (0b1010 = 0xA)
// Since X=1 (U/L=1), the CID cannot be used to form a universal UAA MAC (only a local LAA MAC)
$type = 'ELI-'.eui_bits($mac);;
} else {
$tmp = ipv6linklocal_to_mac48($mac);
if ($tmp !== false) {
$mac = $tmp;
287,11 → 300,16
assert(false); /** @phpstan-ignore-line */
}
}
}
echo sprintf("%-32s %s\n", "Type:", $type);
 
echo "\n";
 
// Show various representations
if ($mac[1] == 'A') {
// Note: There does not seem to exist an algorithm for converting ELI-48 <=> ELI-64
echo sprintf("%-32s %s\n", "ELI-".eui_bits($mac).":", mac_canonize($mac));
} else {
$eui48 = eui64_to_eui48($mac);
echo sprintf("%-32s %s\n", "EUI-48:", (eui_bits($eui48) != 48) ? 'Not available' : $eui48);
if (eui_bits($mac) == 48) {
307,6 → 325,7
$eui64 = mac_canonize($mac);
echo sprintf("%-32s %s\n", "EUI-64:", $eui64);
}
}
 
// Vergabestelle
$ul = hexdec($mac[1]) & 2; // Bit #LSB+1 of Byte 1
315,13 → 334,22
 
// Empfaengergruppe
$ig = hexdec($mac[1]) & 1; // Bit #LSB+0 of Byte 1
$ig_ = ($ig == 0) ? '[0] Individual (Unicast)' : '[1] Group (Multicast)';
$ig_ = ($ig == 0) ? '[0] Unicast (Individual)' : '[1] Multicast (Group)';
echo sprintf("%-32s %s\n", "Transmission type (I/G flag):", $ig_);
 
// Query IEEE registries
// TODO: gilt OUI nur bei Individual UAA? For LAA, should we convert to UAA and then query the registry?
if (count(glob(IEEE_MAC_REGISTRY.DIRECTORY_SEPARATOR.'*.txt')) > 0) {
if ($mac[1] == 'A') {
// Query the CID registry
if (
($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'cid.txt', 'CID', $mac))
) {
echo $x;
}
} else {
// Query the OUI registries
// TODO: Should we try to convert Unicast<=>Multicast if one of them can't be found?
if (
# 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]
# 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.
($x = _lookup_ieee_registry(IEEE_MAC_REGISTRY . DIRECTORY_SEPARATOR . 'iab.txt', 'IAB', $mac)) ||
332,6 → 360,7
echo $x;
}
}
}
 
$vm = '';
// === FAQ "Detection rules which don't have their dedicated page yet" ===
771,8 → 800,11
 
if ((eui_bits($mactest) != eui_bits($lowtest)) || (eui_bits($lowtest) != eui_bits($hightest))) {
$mactest = eui48_to_eui64($mac);
if ($mactest === false) return false; // e.g. trying ELI-48 to ELI-64
$lowtest = eui48_to_eui64($low);
if ($lowtest === false) return false; // e.g. trying ELI-48 to ELI-64
$hightest = eui48_to_eui64($high);
if ($hightest === false) return false; // e.g. trying ELI-48 to ELI-64
}
 
$mactest = strtoupper(preg_replace('@[^0-9A-F]@', '', $mactest));
/trunk/index.php
140,7 → 140,7
<input type="text" name="uuid" value="" style="width:500px"> <input type="submit" value="Go">
</form>
 
<h2>Interprete a MAC address (EUI-48 or EUI-64)</h2>
<h2>Interprete a MAC address (MAC/EUI/ELI)</h2>
 
<p>You can enter an UUID in the following notations:</p>
 
161,7 → 161,7
<li>Information about the registrant, if available.</li>
</ul>
 
<p>Please enter a MAC address:</p>
<p>Please enter a MAC, EUI, ELI, or IPv6-Link-Local address:</p>
 
<form method="GET" action="interprete_mac.php">
<input type="text" name="mac" value=""> <input type="submit" value="Go">