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,

3 responses 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.

  2. Paul D. Nipp says:

    For future readers: Please note that this only runs on Windows, not on Linux (which is probably what your server is running) nor on macOS.

    On Linux, you can find the MAC address using
    ip neigh show

    You could filter the output using grep, awk, or PHP’s preg_match and preg_replace. Although I don’t have code ready at the moment now, this should help you (and me) on the way!

  3. ADITYA SHARMA says:

    it take my mcAfee VPN ADDRESS PLS SUGGEST

Leave a Reply

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