Any PHP code to display the IPaddress of all systems which are connected in a LAN ?

Thanks in advance

Recommended Answers

All 5 Replies

That shall give you the servers IP, then you can use the same $_SERVER['REMOTE_ADDR']; to get the names of computers that connect to the server.
To get the IPs of computers on the LAN, then they must connect to the server in question.

The Manuals are your friend! PHP.net

The above code will display the name and IP of server.Actually I want to display the IP addrsses of all systems which are connected in a LAN by running a php script.Is it possible?

You could grab the server address (as above) and use it to determine the subnet, then perform a ping sweep for active addresses. Not super efficient but I'm not aware of any way of simply listing active addresses.

Another possible method is to use exec() and call the arp-scan tool:

$interface = 'eth0';
$password = 'password';

$cmd = "echo '$password' | sudo -S arp-scan --quiet --interface=$interface --localnet";

exec($cmd, $output);

The variable $output will return an array with the results of the scan. Note that you need to submit the password of a user in the server system, because arp-scan need sueruser privileges.

Using the flag --localnet is the same of submitting a range as, for more info check arp-scan documentation: http://www.nta-monitor.com/wiki/index.php/Arp-scan_User_Guide

That is valid, and more efficient solution, but very system and configuration dependant.

Need to consider:

  • Is this a linux server and is the arp-scan command available?
  • Does PHP have shell and elevation priveleges?
  • Does the OP have root access?
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.