mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
[bug] Fix & extend MAC OUI table updates (#13479)
* get the OUIs from Wireshark CSV instead of macaddress.io which is not free anymore * style * optimize * master wireshark repo * fix Cache::get prefix ordering * fix double cache get Co-authored-by: Tony Murray <murraytony@gmail.com> Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
@@ -155,9 +155,13 @@ class Rewrite
|
|||||||
*/
|
*/
|
||||||
public static function readableOUI($mac)
|
public static function readableOUI($mac)
|
||||||
{
|
{
|
||||||
$key = 'OUIDB-' . (substr($mac, 0, 6));
|
$cached = Cache::get('OUIDB-' . (substr($mac, 0, 6)), '');
|
||||||
|
if ($cached == 'IEEE Registration Authority') {
|
||||||
|
// Then we may have a shorter prefix, so let's try them one ater the other, ordered by probability
|
||||||
|
return Cache::get('OUIDB-' . substr($mac, 0, 9)) ?: Cache::get('OUIDB-' . substr($mac, 0, 7));
|
||||||
|
}
|
||||||
|
|
||||||
return Cache::get($key, '');
|
return $cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1432,17 +1432,35 @@ function cache_mac_oui()
|
|||||||
if ($lock->get()) {
|
if ($lock->get()) {
|
||||||
echo 'Caching Mac OUI' . PHP_EOL;
|
echo 'Caching Mac OUI' . PHP_EOL;
|
||||||
try {
|
try {
|
||||||
$mac_oui_url = 'https://macaddress.io/database/macaddress.io-db.json';
|
$mac_oui_url = 'https://gitlab.com/wireshark/wireshark/-/raw/master/manuf';
|
||||||
|
//$mac_oui_url_mirror = 'https://raw.githubusercontent.com/wireshark/wireshark/master/manuf';
|
||||||
|
|
||||||
echo ' -> Downloading ...' . PHP_EOL;
|
echo ' -> Downloading ...' . PHP_EOL;
|
||||||
$get = Requests::get($mac_oui_url, [], ['proxy' => get_proxy()]);
|
$get = Requests::get($mac_oui_url, [], ['proxy' => get_proxy()]);
|
||||||
echo ' -> Processing ...' . PHP_EOL;
|
echo ' -> Processing CSV ...' . PHP_EOL;
|
||||||
$json_data = $get->body;
|
$csv_data = $get->body;
|
||||||
foreach (explode("\n", $json_data) as $json_line) {
|
foreach (explode("\n", $csv_data) as $csv_line) {
|
||||||
$entry = json_decode($json_line);
|
unset($oui);
|
||||||
if ($entry && $entry->{'assignmentBlockSize'} == 'MA-L') {
|
$entry = str_getcsv($csv_line, "\t");
|
||||||
$oui = strtolower(str_replace(':', '', $entry->{'oui'}));
|
|
||||||
|
$length = strlen($entry[0]);
|
||||||
|
$prefix = strtolower(str_replace(':', '', $entry[0]));
|
||||||
|
|
||||||
|
if (is_array($entry) && count($entry) >= 3 && $length == 8) {
|
||||||
|
// We have a standard OUI xx:xx:xx
|
||||||
|
$oui = $prefix;
|
||||||
|
} elseif (is_array($entry) && count($entry) >= 3 && $length == 20) {
|
||||||
|
// We have a smaller range (xx:xx:xx:X or xx:xx:xx:xx:X)
|
||||||
|
if (substr($prefix, -2) == '28') {
|
||||||
|
$oui = substr($prefix, 0, 7);
|
||||||
|
} elseif (substr($prefix, -2) == '36') {
|
||||||
|
$oui = substr($prefix, 0, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($oui)) {
|
||||||
|
echo "Adding $oui, $entry[2]" . PHP_EOL;
|
||||||
$key = 'OUIDB-' . $oui;
|
$key = 'OUIDB-' . $oui;
|
||||||
Cache::put($key, $entry->{'companyName'}, $mac_oui_cache_time);
|
Cache::put($key, $entry[2], $mac_oui_cache_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
Reference in New Issue
Block a user