PHP域名Whois查询API接口源码,接口数据来自于站长工具的Whois的查询工具。
API接口代码
<?php error_reporting(0); header('charset=utf-8'); if (!empty($_GET['domain'])) {//判断是否有get值 /*获取网页内容*/ $curl = curl_init(); $httpheader[] = "Accept:*/*"; $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8"; $httpheader[] = "Connection:close"; $httpheader[] = "Referer:https://whois.chinaz.com"; $httpheader[] = "User-agent:Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 MicroMessenger/4.3.2"; curl_setopt($curl, CURLOPT_HTTPHEADER, $httpheader); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, 'https://whois.chinaz.com/' . str_replace(array("https://", "https://"), "", $_GET['domain']));//去除https://和https:// $text = curl_exec($curl); curl_close($curl); /*对获取的网页内容截取*/ preg_match('/注册商</div><div class="fr WhLeList-right"><div class="block ball"><span>(.*?)</span>/i', $text, $zhuceshang); preg_match('/联系人</div><div class="fr WhLeList-right block ball lh24"><span>(.*?)</span>/i', $text, $contacts); preg_match('/创建时间</div><div class="fr WhLeList-right"><span>(.*?)</span>/i', $text, $chuangjianshijian); preg_match('/过期时间</div><div class="fr WhLeList-right"><span>(.*?)</span>/i', $text, $guoqishijian); preg_match('/DNS</div><div class="fr WhLeList-right">(.*?)<br/></div>/i', $text, $dns); preg_match('/联系电话</div><div class="fr WhLeList-right block ball lh24"><span>(.*?)</span>/i', $text, $phone); preg_match('/公司</div><div class="fr WhLeList-right"><div class="block ball"><span>(.*?)</span>/i', $text, $gongsi); preg_match('/<div class="fl WhLeList-left">联系邮箱</div><div class="fr WhLeList-right block ball lh24"><span>(.*?)</span>/i', $text, $mail); $dnsarray = explode("<br/>", $dns[1]); //对多个dns分组 /*对几个可能为空的值判断*/ if (!empty($gongsi[1])) { $gongsi = $gongsi[1]; } else { $gongsi = '-'; } if (!empty($phone[1])) { $phone = $phone[1]; } else { $phone = '-'; } if (!empty($zhuceshang[1])) { $zhuceshang = $zhuceshang[1]; } else { $zhuceshang = '-'; } /*输出并结束程序*/ exit(' <!--数据来源:站长工具 whois.chinaz.com --> <p><strong>注册商:</strong>' . $zhuceshang . '</p> <p><strong>联系人:</strong>' . $contacts[1] . '</p> <p><strong>公司:</strong>' . $gongsi . '</p> <p><strong>邮箱:</strong>' . $mail[1] . '</p> <p><strong>电话:</strong>' . $phone . '</p> <p><strong>创建时间:</strong>' . $chuangjianshijian[1] . '</p> <p><strong>过期时间:</strong>' . $guoqishijian[1] . '</p> <p><strong>DNS:</strong>' . "$dnsarray[0]t$dnsarray[1]" . '</p>'); } else { //如果get值为空则显示'Error'并结束程序 exit('请填写域名'); }
API接口使用方法:网站/接口名称.php/?domain=这这里是要查询的域名
本文转载自:精准像素:11px.cn ,感谢作者分享实用知识