if ( is_null($_GET['mac']) || preg_match("/[^-:a-zA-Z0-9 ]/", $_GET['mac']) ) {
die("Hay que introducir una mac o parecido. Ej: https://www.latinsud.com/pub/oui/oui.php?mac=00:11:22:33:44:54");
}
$mac = preg_replace('/[^a-fA-F0-9]/', "", $_GET['mac']);
$mac = substr($mac, 0, 2) . "-" . substr($mac, 2, 2) . "-" . substr($mac, 4, 2);
$tocho = file("files/oui.txt");
$origen = 0;
$cuenta = 0;
$encontrado = 0;
// Buscar en el fichero, linea a linea
foreach ($tocho as $nlin => $linea) {
// Match
if (stripos($linea, $mac) !== false ) {
if ($cuenta > 10) {
die("...");
}
$encontrado = 1;
}
// Si linea vacia: cambio de parrafo, imprimir, etc
if ($linea == "\r\n") {
if ( $encontrado ) {
// Imprimir el parrafo si toca
for ($l = $origen; $l < $nlin; $l++) {
print $tocho[$l];
}
echo "
";
$cuenta++;
}
$origen = $nlin;
$encontrado = 0;
}
}
// passthru("grep -A4 -- " . $_GET['mac'] . " oui.txt | /usr/bin/head -n 20 | sed 's/^--/
/'");