4
Contributors
5
Replies
53
Views
4 Years
Discussion Span
Last Post by |-|x
1

gethostbyaddr($_SERVER['REMOTE_ADDR']);
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

Edited by Octet

0

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?

0

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.

0

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);
print_r($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 192.168.1.0/24, for more info check arp-scan documentation: http://www.nta-monitor.com/wiki/index.php/Arp-scan_User_Guide

0

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?
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.