<?php
highlight_file(__FILE__);
exit;
if (empty($argv[1]))
die("No oui file given");
$ouis = explode("\r\n", file_get_contents($argv[1]));
// This menufacturers array was put together by checking which names occurred the most (php -r 'file_open();foreach line{hashtable[manufacturer]++;} asort(hashtable); print_r.')
$manufacturers = array("cisco", "nokia", "intel", "hewlett packard", "texas instruments", "nintendo", "motorola", "apple", "samsung", "sony", "d-link", "ibm", "juniper", "hon hai", "3com", "dell", "xerox", "huawei", "rim", "lg electronics", "giga-byte", "htc", "toshiba", "avm", "microsoft", "netgear", "tp-link", "alps", "zyxel", "seagate");
// Determine the longest name in order to neatly format the list later
foreach ($manufacturers as $manufacturer)
$maxmanufacturerlength = max($maxmanufacturerlength, strlen($manufacturer));
$count["none"]++;
foreach ($ouis as $oui) {
$oui = explode("\t", $oui);
//$count[$oui[2]]++;
foreach ($manufacturers as $manufacturer) {
if (stripos($oui[2], $manufacturer) !== false)
$count[$manufacturer]++;
else
$count["none"]++;
}
}
arsort($count);
$perblock = pow(2,24);
foreach ($count as $oui=>$blocks) {
$min = number_format(($blocks - 1) * $perblock);
$max = number_format($blocks * $perblock);
$ouiappendspaces = str_repeat(" ", max(0, $maxmanufacturerlength - strlen($oui)));
echo "$blocks\t$oui$ouiappendspaces\t($min - $max)\n";
}