Last updated on May 21st, 2016 at 11:24 pm
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}'"); ?>
thanks for sharing it’s working!
Hi Author, thank you very much I read some of your posts whenever I have time. Your posts have been very helpful to me. Thanks. Go ahead like this. I visit this website from time to time https://kod***.net/233/how-to-get-mac-address-of-client-machine-in-php
Thanks Janifer!! for your kind words 🙂