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

Posted on 2006-04-08
Last Modified: 2013-12-05
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
Question by:mnb93
    LVL 142

    Accepted Solution

    here the full sample on *nix, using ifconfig:

    on windows, the command line to use would be net config workstation;en-us;118623

    LVL 11

    Assisted Solution


    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.
    LVL 5

    Author Comment

    I can now get it in unix, how about that code for windows?
    LVL 5

    Author Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now