0

I was trying to get IP and MAC address of client using PHP but I am unable to get that. I tried below code but it gives wrong MAC address -

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);
$mac=substr($mycom,($pmac+36),17); // Get Physical Address
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • @Archer to me it seems that OP is trying to get the _servers_ MAC addy (since he is issuing `ipconfig`), where do you see _client_? – kayess Nov 26 '15 at 12:07
  • @kayess My mistake, if it was one. The mention of Javascript says client to me. Does it not you? – Reinstate Monica Cellio Nov 26 '15 at 12:08
  • @Archer OP is probably confused on the wording, might worth asking to correct it, however the code is PHP, so I assumed it might only be server side. – kayess Nov 26 '15 at 12:11
  • 1
    @kayess We've both made assumptions here. OP, is this the server mac address or client mac address you want? – Reinstate Monica Cellio Nov 26 '15 at 12:12
  • i want client mac address. – mmthedependable Nov 26 '15 at 12:45
  • @mmthedependable then please edit your question accordingly. – kayess Nov 26 '15 at 12:46
  • 7
    Related and possible duplicate of: [http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php](http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php) and [http://stackoverflow.com/questions/1420381/how-can-i-get-the-mac-and-the-ip-address-of-a-connected-client-in-php](http://stackoverflow.com/questions/1420381/how-can-i-get-the-mac-and-the-ip-address-of-a-connected-client-in-php). – kayess Nov 26 '15 at 13:01
  • Curiously, the code in the question appears to be from a (rather flawed) answer to one of the possible duplicates. http://stackoverflow.com/a/33537707/874188 – tripleee Nov 26 '15 at 13:14

2 Answers2

0

Like the commenters say on the question, you will not be able to get the client MAC since the PHP runs on the server, but you can get the client IP by checking $_SERVER['REMOTE_ADDR'] or if the user is behind a proxy, you can use $_SERVER['HTTP_X_FORWARDED_FOR']

Christian
  • 915
  • 1
  • 8
  • 13
0

As mentioned by many users its not possible to get user MAC_ADDRESS. To get user ip try this

function getUserIP()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
Skyyy
  • 1,539
  • 2
  • 23
  • 60