Thursday, November 17, 2011

PHP CODE to Find MAC Address and HOST Name

Using following code will help you find MAC Address and Host Name of Selected IP.  To execute following code you need to change the security permission of cmd.exe
Go to \Windows\System32\cmd.exe right click on it and select properties. Select user Internet Guest Accounts/IUSER….
Then add the full control. Follow the picture.
$hostname = gethostbyaddr(trim(''));
$ip = '';

SYSTEM(`ping $ip -n 1 && arp -a`);
$output = `arp $ip -a`;
$line = $output;

$pos = strpos("$line","$ip");

$mac = str_replace("$ip","", $line);
$mac1 = str_replace("dynamic","", $mac);
$mac2 = trim(substr($mac1,86));

    if ($ip == $hostname)
            $host = '';  
            $host = $hostname;  
echo 'Host Name   :    ', $host;
echo '<BR>';
echo 'Mac Address :    ', $mac2;


No comments: