• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

Get MAC Address of the SERVER in Windows *nix (Linux,Mac,FreeBSD etc...) and Solaris Sparc

How can I get the MAC Address of the SERVER in Windows and *nix (Linux,Mac,FreeBSD, Solaris Sparc etc...) (*nix support must be at least those mentioned) in PHP
  • 2
2 Solutions
Guy Hengel [angelIII / a3]Billing EngineerCommented:
here the full sample on *nix, using ifconfig:

on windows, the command line to use would be net config workstation


Here's the unix PHP code, which will work ONLY if your host allows access to the ifconfig command:



   passthru('/sbin/ifconfig | grep ether');

   $dump = ob_get_contents();

   preg_match('/[A-F0-9]{2}:[A-F0-9]{2}:[A-F0-9]{2}:[A-F0-9]{2}:[A-F0-9]{2}:[A-F0-9]{2}/i', $dump, $mac);

   $mac_address = $mac[0];



Note that the server architecture and version of ifconfig will give varying results, so you first need to log onto the server as the Web Server user and do the following:

   1) Test that you have access to ifconfig:


   2) Find the path to ifconfig to put into your passthru command:

      which ifconfig

   3) Check that the output from ifconfig (in step (1)) includes a single line with the word 'ether' that matches the IP address of the server.  Note that some servers are configured with multiple network cards and IP addresses, so this may not be as simple as you imagine.

The Windows version is less complex in some areas and harder in others.  Get the unix method working first, and I'll post some code for the Windows version if you are happy you want to continue with this approach.
mnb93Author Commented:
I can now get it in unix, how about that code for windows?
mnb93Author Commented:

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now