• 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
0
mnb93
Asked:
mnb93
  • 2
2 Solutions
 
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
 
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

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