How to detect the MAC address of a device in PHP

In this article, we will learn how to get the MAC address or physical address of a system using PHP.

First of all, let me clear the concept of the MAC address.

What is a MAC address?

It abbreviated as media access control. A MAC address is a unique id of a device in the network interface controller (NIC).

It is also known as a physical address, an Ethernet hardware address, and a hardware address.



How to get MAC address using system command in PHP

The system() command gathers the information from the configuration file (ipconfig file). From that information file, we have to access only the physical address. The script is as follows,

   //Buffering the output
   //Getting configuration details 
   system('ipconfig /all');  
   //Storing output in a variable 
   // Clear the buffer  
   //Extract only the physical address or Mac address from the output
   $mac = "Physical";  
   $pmac = strpos($configdata, $mac);
   // Get Physical Address  
   //Display Mac Address  
   echo $macaddr;  



In this way, we can extract the MAC address of a computer. If you have any doubts about this article, leave a comment below.

See also,

One response to “How to detect the MAC address of a device in PHP”

  1. Namit Singh says:

    This is now working showing blank page. Please if you have any other solution please post it.

Leave a Reply

Your email address will not be published.