How PHP Gets the domain name IP address code function

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.