The code is as follows |
Copy Code |
$DM = ' www.111cn.net '; $ip = gethostbyname ($DM); echo gethostbyaddr ($IP); Echo $ip; |
Two output results are the same,
/*
About gethostbyname syntax
String gethostbyname (String $hostname)
Returns the IPv4 address of the Internet host specified by the host name
Returns the IPv4 address of the Internet host specified by hostname
Here's an example of this is the best way I've proposed to address any host name to the IP address when it's fast, reliable, and has timed out support! An invalid address, such as a Unicode string, returns 4? seconds, not 8 calls to gethostbyname?! It can only be with Unix though.
*/
The code is as follows |
Copy Code |
function Getaddrbyhost ($host, $timeout = 3) { $query = ' nslookup-timeout= $timeout-retry=1 $host '; if (Preg_match ('/Address: (. *)/', $query, $matches)) return Trim ($matches [1]); return $host; } |
/*
GETHOSTBYADDR is to get the Internet host name for a specific IP address
The code is as follows |
Copy Code |
String gethostbyaddr (String $ip _address) |
*/
The code is as follows |
Copy Code |
$hostname = gethostbyaddr ($_server[' remote_addr ')); Echo $hostname; |
Site Original tutorial reproduced www.111cn.net