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
LVL 5
mnb93Asked:
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:
http://www.codecomments.com/archive128-2004-5-205508.html

on windows, the command line to use would be net config workstation
http://support.microsoft.com/default.aspx?scid=kb;en-us;118623

0

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
siliconbritCommented:

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

<?php

   ob_start();

   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];

   ob_end_clean();

?>

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:

      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.
0
mnb93Author Commented:
I can now get it in unix, how about that code for windows?
0
mnb93Author Commented:
Um...
0
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.