Jump to content

Recommended Posts

Hello,

 

I am using

 

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$arp = "/usr/sbin/arp";
$mac = shell_exec("sudo $arp -an " . $ip);
preg_match('/..:..:..:..:..:../',$mac , $matches);
$mac = @$matches[0];

echo $mac

?>

 

to see/verify in my browser if there will be a return for echo $mac, but there is nothing appearing on the webpage

 

and using var_dump($mac) returns NULL on the webpage.

 

Basically, I would want to get the client mac address on LAN.

 

Hoping for your favorable response. Thank you.

Edited by xmen
Link to comment
https://forums.phpfreaks.com/topic/268984-get-mac-address-locally/
Share on other sites

I am not familiar with most Linux commands, however I would say that to command you have used will only get the MAC address of your server rather than the client and as you use the clients IP ... that could be where you are going wrong. Maybe see what the following outputs...

 

$ip = $_SERVER [ 'REMOTE_ADDR' ];
$mac = shell_exec ( "sudo /usr/sbin/arp -an $ip" );
var_dump ( $mac );

 

If no output is received, chances are ... what you are trying to do will not be possible.

You cannot use the IP-address to get the MAC address with ARP, only the hostname. Which is why you're not getting any results from the shell command.

You need to retrieve all of the output from it, loop through each line, and do a string match for the IP-address.

 

Note that MAC-addresses should not be relied upon for any kind of security. It is simply a way for the hardware to recognize each other, and software running on layer 6/7 of the OSI model should have no knowledge of this what so ever.

Add your var_dump($mac) just after your shell_exec function and see what output you are getting. Did you setup an entry in sudo so that you can run the command without having to enter a password?

 

Have you checked that $ip is a valid LAN address and not a WAN address or 127.0.0.1?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.