Last updated on May 21st, 2016 at 11:24 pm

VN:F [1.9.22_1171]
Rating: 6.7/10 (29 votes cast)

Get MAC address using PHP

Get the MAC (Media Access Control) address of a system using php. We are having 2 separate code. One for Windows and other for Linux.

On Windows Machine

ob_start();
system('ipconfig /all'); 
$mycom=ob_get_contents(); // Capture the output into a variable
ob_clean(); 
$findme = "Physical";
$pos = strpos($mycom, $findme);
$macp=substr($mycom,($pos+36),17);
echo "The mac id of this system is :".$macp;

On Linux Machine

It is very easy in Linux, Just run the ip addr command and grep for ‘link/ether’. Then use awk to pring the 2nd variable.

<?php
echo "The mac id of this system is :";
system("/sbin/ip addr|/bin/grep link/ether | /bin/awk '{print $2}'"); 
?>
VN:F [1.9.22_1171]
Rating: 6.7/10 (29 votes cast)
One thought on “Get MAC address using PHP”

Leave a Reply

Your email address will not be published. Required fields are marked *