Reputation: 861
I'm attempting to make a reverse DNS function using the gethostbyname()
function, but whenever I input an IP string, say, '104.16.34.249'
(SO's IP), it returns that string as the result. What am I doing wrong?
Code (neither works):
$table['ip-host']=gethostbyname($args['args']);
$table['ip-host']=gethostbyaddr($args['args']);
Upvotes: 0
Views: 1295
Reputation: 944
This is exactly what the gethostbyname() was designed to do. It returns the IP address if you enter the host name. And if you enter the IP address it will return IP address back to you. If you want to get the host name back then use gethostbyaddr().
http://php.net/manual/en/function.gethostbyaddr.php
Upvotes: 2
Reputation: 4104
It is expected behaviour. gethostbyname()
takes in a domain and converts it to an IP address.
Returns the IPv4 address of the Internet host specified by hostname.
You get a host (IP) by name (domain name).
Try:
<?php
echo gethostbyname('www.example.com');
?>
You should get an IP of the server hosting www.example.com.
Upvotes: 1