emersonbroga
11/18/2014 - 9:54 PM

GetMacAddress

GetMacAddress

<?php

$ipAddress=$_SERVER['REMOTE_ADDR'];

#run the external command, break output into lines
$result = `arp -n $ipAddress`;

// $result expample '? (192.168.1.9) at e0:f8:47:2a:12:b8 on en1 ifscope permanent [ethernet]'

// using explode
$parts = explode(' at ', $result); 
$parts = explode(' on ', $parts[1]);
$macAddress = $parts[0];


// using regex...
//preg_match('/\sat\s(.*?)\son\s/',$result, $matches); 
//$macAddress = $matches[1];





die('The mac address is: ' . $macAddress);
?>