Ec (2); & nbsp; the Code is as follows: copy the code $ dmwww.111cn.net; $ ipgethostbyname ($ dm); echogethostbyaddr ($ ip); echo $ ip; the two outputs are the same, * gethostbyname syntax stringgethostbyname (stri script ec (2); script
The Code is as follows: |
|
$ Dm = 'www .111cn.net '; $ Ip = gethostbyname ($ dm ); Echo gethostbyaddr ($ ip ); Echo $ ip; |
// The two outputs are the same,
/*
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
The following is an example. This is the best method I have proposed to solve the problem of any host name to an IP address. It is fast, reliable, and has timed out! An invalid address, such as a unicode string, returns the last 4? Seconds instead of 8 calls gethostbyname ?! It can only work with unix though.
*/
The Code is as follows: |
|
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 used to obtain a specific IP address corresponding to the internet host name.
The Code is as follows: |
|
String gethostbyaddr (string $ ip_address) |
*/
The Code is as follows: |
|
$ Hostname = gethostbyaddr ($ _ server ['remote _ addr ']); Echo $ hostname; |
This site original tutorial reprinted www.111cn.net