Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get the mac address on LAN connected machine but I have got the following error,

Connected successfullyNo mac address for 127.0.0.1 not found

What I have tried:

I have tried this code,


<?php

$link = mysqli_connect('localhost', 'mysql_user', '');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysqli_close($link);


$ip = $_SERVER['REMOTE_ADDR'];
$mac = shell_exec('arp -a'. escapeshellarg($ip));
$findme = "Physical";
$pos = strpos($mac, $findme);
$macp = substr($mac,($pos+42),26);

if(empty($mac))
{
die("No mac address for $ip not found");
}
echo "mac address for $ip: $macp";

?>
Posted
Updated 4-Apr-17 21:23pm

1 solution

MAC (Media Access Control) addresses are associated with harwdare network interfaces. But 127.0.0.1 is the virtual loopback interface and virtual interfaces have no MAC address.

To test your code you have to connect from a client machine that is not the server itself.
 
Share this answer
 
Comments
Member 13079470 6-Apr-17 1:15am    
please describe in details.
How to solve this problem?
Jochen Arndt 6-Apr-17 2:48am    
There is no problem.
Your code is working as expected.

You have asked for "get mac address on lan connected machine" but your script has been called for a connection from your local machine which is indicated by the IP address 127.0.0.1

To get the MAC address for another machine you have to establish a connection from that machine first.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900