How can I obtain a domain name through an ip address ?? I use gethostbyaddr ('put IP' inside); each time only the ip address is returned instead of the domain name. it seems that only 127.0.0.1 can be input to return the domain name, neither Baidu nor Google, how can this function be used !!!! Functiongethost ($ ip) {& How do I get a domain name through ip address ??
I use gethostbyaddr ('put IP' inside); each time only the ip address is returned instead of the domain name. it seems that only 127.0.0.1 can be input to return the domain name, neither Baidu nor Google, how can this function be used !!!!
Function gethost ($ ip)
{
Return (preg_match ('/^ (? : 25 [0-5] | 2 [0-4] \ d | 1 \ d | [1-9] \ d | \ d )(? : [.]
(? : 25 [0-5] | 2 [0-4] \ d | 1 \ d | [1-9] \ d | \ d )) {3} $/', $ ip ))? Gethostbyaddr ($ ip): false;
}
------ Solution --------------------
PHP code
Function getContent ($ url) {$ content = file_get_contents ($ url); return $ content;} function getResult ($ ip) {$ pagesize = 10; $ page = 1; $ url = "http://cn.bing.com/search? Q = ip % 3A $ ip & first = $ page "; $ result = array (); do {$ url =" http://cn.bing.com/search? Q = ip % 3A $ ip & first = $ page "; $ content = getContent ($ url); $ pattern = "/([A-zA-Z0-9 \.] *) (? :\/.*)? <\/Cite>/isU "; preg_match_all ($ pattern, $ content, $ matches); $ result = array_merge ($ result, $ matches [1]); $ nextpage = strpos ($ content, "next page"); $ page = $ page + $ pagesize;} while ($ nextpage ); $ result = array_values (array_unique ($ result); return $ result;} // call method $ result = getResult ("220.181.111.85 "); // $ result = getResult ("117.79.93.222"); // csdnecho"";print_r($result);