<?php
function get_mac() {
    $output=null;
    $retval=null;
    $remote = isset($_SERVER["REMOTE_ADDR"]) ? $_SERVER["REMOTE_ADDR"] : '127.0.0.1';
    exec("ping -W 1 -c 1 $remote", $output, $retval);
    //print($output);
    if ($retval == '0') {
        $output = null;
        $retval = null;
        exec("ip neigh | grep -e $remote | grep -o 'lladdr.* '", $output, $retval);
        if (count($output) > 0) {
            $mac = strtoupper(str_replace('lladdr ', '', $output[0]));
            $_SESSION['mac'] = $mac;
        } else {
            $mac = $remote;
            $_SESSION['mac'] = $remote;
        }
    }
    if ($mac != "") {
	return $mac;
    } else {
	return "00:00:00:00:00:00";
    }
}

?>