Skip to content

Instantly share code, notes, and snippets.

@emersonbroga
Last active August 29, 2015 14:09
Show Gist options
  • Save emersonbroga/9e02b249773ec2c360be to your computer and use it in GitHub Desktop.
Save emersonbroga/9e02b249773ec2c360be to your computer and use it in GitHub Desktop.
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);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment