ホームページ  >  記事  >  バックエンド開発  >  IP経由でドメイン名を取得するにはどうすればよいですか?

IP経由でドメイン名を取得するにはどうすればよいですか?

WBOY
WBOYオリジナル
2016-06-13 13:17:131113ブラウズ

IPでドメイン名を取得するにはどうすればよいですか? ?
私は gethostbyaddr('put ip in it'); を毎回使用していますが、ドメイン名ではなく IP のみを返します。ドメイン名は 127.0.0.1 を入力することによってのみ返されるようですが、これは Baidu では機能しません。またはGoogle。この機能はどのように機能しますか? ! ! !

function gethost ($ip)
{
return ( preg_match('/^(?:25[0-5]|2[0-4]d|1dd|[1-9 ]d|d)(?:[.]
(?:25[0-5]|2[0-4]d|1dd|[1-9]d|d)){3}$/' , $ip) ) ? gethostbyaddr($ip) : false;

}

-----解決策------------ -------

PHP コード

関数 getContent($url){
    $content=file_get_contents($url);
    $content を返します。
}
 
関数 getResult($ip){
    $ページサイズ=10;
    $ページ=1;
    $url="http://cn.bing.com/search?q=ip%3A$ip&first=$page";
    $result=array();
    する
    {
        $url="http://cn.bing.com/search?q=ip%3A$ip&first=$page";
        $content=getContent($url);
        $pattern="/<cite>([a-zA-Z0-9.]*)(?:/.*)?</cite>/isU";
        preg_match_all($pattern, $content, $matches);
        $result=array_merge($result,$matches[1]);
        $nextpage=strpos($content, "次のページ");
        $page=$page+$pagesize;
    }while($nextpage);
      
    $result=array_values(array_unique($result));
      
    $result を返します。
}
 
// メソッドを呼び出す
$result=getResult("220.181.111.85");
//$result=getResult("117.79.93.222");//csdn
echo "<pre class="brush:php;toolbar:false">";
print_r($result); <div class="clear"></div>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。