gethostbyaddr

string gethostbyaddr(string IP_address) 

Gets the human-readable name for an IP address.

Returns:

Internet hostname; IP_address argument on error

Description:

gethostbyaddr() performs a DNS lookup of an Internet IP address and returns the corresponding domain name. If no name exists, the function returns the IP_address argument.

Availability:

UNIX, Windows

Version:

3+, 4+

See also:

gethostbyname() 
gethostbynamel() 

Example:

23.5. Find the hostname for an IP address
<?php 
$ip = '18.29.1.31'; 
$host = gethostbyaddr ($ip); 

if ($ip != $host) 
   echo "The hostname for <i>$ip</i> is <i>$host</i>."; 
else 
   echo "I could not successfully look up <i>$ip</i>."; 
?> 

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.