Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Posts
    149
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Get MAC adress using PHP

    I want to get MAC address with php script.
    Is it possible to get MAC address directly using PHP script?

    If any one have idea about MAC address please help to to get.

    Thanks in advance

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,332
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    AFAIK No it can't be done in PHP. The server is on a totally different subnet and has no access to your subnet to scan it for mac addresses etc.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Are you referring to the MAC address of the server or the client?

  • #4
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    // Get the arp executable path
    $location = `which arp`;
    // Execute the arp command and store the output in $arpTable
    $arpTable = `$location`;
    // Split the output so every line is an entry of the $arpSplitted array
    $arpSplitted = split("\n",$arpTable);
    // Get the remote ip address (the ip address of the client, the browser)
    $remoteIp = $GLOBALS['REMOTE_ADDR'];
    // Cicle the array to find the match with the remote ip address
    foreach ($arpSplitted as $value) {
    // Split every arp line, this is done in case the format of the arp
    // command output is a bit different than expected
    $valueSplitted = split(" ",$value);
    foreach ($valueSplitted as $spLine) {
    if (preg_match("/$remoteIp/",$spLine)) {
    $ipFound = true;
    }
    // The ip address has been found, now rescan all the string
    // to get the mac address
    if ($ipFound) {
    // Rescan all the string, in case the mac address, in the string
    // returned by arp, comes before the ip address
    // (you know, Murphy's laws)
    reset($valueSplitted);
    foreach ($valueSplitted as $spLine) {
    if (preg_match("/[0-9a-f][0-9a-f][:-]".
    "[0-9a-f][0-9a-f][:-]".
    "[0-9a-f][0-9a-f][:-]".
    "[0-9a-f][0-9a-f][:-]".
    "[0-9a-f][0-9a-f][:-]".
    "[0-9a-f][0-9a-f]/i",$spLine)) {
    return $spLine;
    }
    }
    }
    $ipFound = false;
    }
    }
    return false;
    }

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,332
    Thanks
    60
    Thanked 526 Times in 513 Posts
    Blog Entries
    4
    Quote Originally Posted by qeemat View Post
    // Get the arp executable path
    $location = `which arp`;
    // Execute the arp command and store the output in $arpTable
    $arpTable = `$location`;
    Having just run those two lines of code, I got these results from var_dump() for both those variables:
    NULL
    NULL

    The comment mentions executing the arm command yet you show no way of doing so. Are you using exec, system or what?

    At the moment your code doesn't really do much to help anyone. IF you're going to sign up to post that then I think the least you could do is make sure its ready to use.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #6
    Regular Coder
    Join Date
    Jan 2012
    Posts
    134
    Thanks
    0
    Thanked 32 Times in 32 Posts
    No matter what programming language you use, it's impossible to get the MAC address of any machine outside of your network; it's simply not available.

    If this PHP code is being accessed locally, then you can use PHP to execute certain windows/linux commands to get the MAC. If this is the case, let us know.

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by tangoforce View Post
    The comment mentions executing the arm command yet you show no way of doing so. Are you using exec, system or what?
    shell_exec()


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •