xmen Posted October 2, 2012 Share Posted October 2, 2012 (edited) 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 October 2, 2012 by xmen Quote Link to comment https://forums.phpfreaks.com/topic/268984-get-mac-address-locally/ Share on other sites More sharing options...
JLT Posted October 2, 2012 Share Posted October 2, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/268984-get-mac-address-locally/#findComment-1382179 Share on other sites More sharing options...
Christian F. Posted October 2, 2012 Share Posted October 2, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/268984-get-mac-address-locally/#findComment-1382186 Share on other sites More sharing options...
kicken Posted October 2, 2012 Share Posted October 2, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/268984-get-mac-address-locally/#findComment-1382205 Share on other sites More sharing options...
jazzman1 Posted October 2, 2012 Share Posted October 2, 2012 Do you want to sniff the LAN or you are an admin and have full access to the router ? Quote Link to comment https://forums.phpfreaks.com/topic/268984-get-mac-address-locally/#findComment-1382233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.