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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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;en-us;118623


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.