how can I find the system mac address?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arvind vohra
    New Member
    • Jan 2012
    • 12

    how can I find the system mac address?

    this code is not working online

    Code:
    ob_start(); // Turn on output buffering
    system('ipconfig /all');
    $mycom=ob_get_contents(); // Capture the output into a variable
    ob_clean(); // Clean (erase) the output buffer
    
    $findme = "Physical";
    $pmac = strpos($mycom, $findme); // Find the position of Physical text
    $mac=substr($mycom,($pmac+36),17); // Get Physical Address
    echo "<br>";
    echo $mac;
    Last edited by acoder; Jan 12 '13, 03:30 PM. Reason: Please use [code] tags when posting code
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    What OS is your server running?

    The ipconfig command is a Windows command, so it will not work on Linux servers. (Which is by far the dominant OS for PHP hosts.) The Linux equivalent is ifconfig, although the output it generates is not the same. You'd have to rewrite the parsing portion of the code to match that output.

    Also note that it's not uncommon for shared hosts to disable functions like that for security reasons. You may want to add some error checking to make sure both the function and the call are successful.

    Comment

    Working...