mercoledì 16 ottobre 2013

Recuperare il Mac Address del Server in PHP

PHP

ob_start();


if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
    $comando = 'ipconfig /all';
} else {
    $comando = "/sbin/ifconfig | grep ether";
}

passthru($comando);
$dump = ob_get_contents();

$risultato = preg_match('/[A-F0-9]{2}[:\-][A-F0-9]{2}[:\-][A-F0-9]{2}[:\-][A-F0-9]{2}[:\-][A-F0-9]{2}[:\-][A-F0-9]{2}/i', $dump, $mac);

$mac_address = $mac[0];

ob_end_clean();


if ($risultato == "1")
    echo "Trovato: " . $mac_address;


/PHP

Nessun commento: