I'm trying to determine the hostname of devices on the network to store to show more human information to my users as my source file unfortunately doesn't contain this (and is dynamic so I need to maintain this info elsewhere), however the built in PHP function gethostbyaddr() doesn't work.
For example, I have a device at 10.0.60.1
with hostname Phone-Chris
(I don't care about the domain portion, just the hostname itself).
When I use:
<?php
$hostname = gethostbyaddr("10.0.60.1");
echo "$hostname";
?>
It just returns the IP address (which indicates that the lookup failed). If I change it to 8.8.8.8
, it works as expected and show google-public-dns-a.google.com
. I get the impression this function probably won't do what I want as it seems to rely on reverse lookups.
How can I determine what the hosename is of a device on the network so that I can store that information in this manner? (i.e., return Phone-Chris
).
This has to do with reverse dns lookups... you aren't going to get any love on this one from php for the masses. Only situation where is would work that I can tell is one where the client and the webserver share the same dns server.