PHP whois查询类定义与用法示例


Posted in PHP onApril 03, 2019

本文实例讲述了PHP whois查询类定义与用法。分享给大家供大家参考,具体如下:

whois.class.php

<?php
class Whois{
private $WHOIS_SERVERS = array(
"com" => array("whois.verisign-grs.com","whois.crsnic.net"),
"net" => array("whois.verisign-grs.com","whois.crsnic.net"),
"org" => array("whois.pir.org","whois.publicinterestregistry.net"),
"info" => array("whois.afilias.info","whois.afilias.net"),
"biz" => array("whois.neulevel.biz"),
"us" => array("whois.nic.us"),
"uk" => array("whois.nic.uk"),
"ca" => array("whois.cira.ca"),
"tel" => array("whois.nic.tel"),
"ie" => array("whois.iedr.ie","whois.domainregistry.ie"),
"it" => array("whois.nic.it"),
"li" => array("whois.nic.li"),
"no" => array("whois.norid.no"),
"cc" => array("whois.nic.cc"),
"eu" => array("whois.eu"),
"nu" => array("whois.nic.nu"),
"au" => array("whois.aunic.net","whois.ausregistry.net.au"),
"de" => array("whois.denic.de"),
"ws" => array("whois.worldsite.ws","whois.nic.ws","www.nic.ws"),
"sc" => array("whois2.afilias-grs.net"),
"mobi" => array("whois.dotmobiregistry.net"),
"pro" => array("whois.registrypro.pro","whois.registry.pro"),
"edu" => array("whois.educause.net","whois.crsnic.net"),
"tv" => array("whois.nic.tv","tvwhois.verisign-grs.com"),
"travel" => array("whois.nic.travel"),
"name" => array("whois.nic.name"),
"in" => array("whois.inregistry.net","whois.registry.in"),
"me" => array("whois.nic.me","whois.meregistry.net"),
"at" => array("whois.nic.at"),
"be" => array("whois.dns.be"),
"cn" => array("whois.cnnic.cn","whois.cnnic.net.cn"),
"asia" => array("whois.nic.asia"),
"ru" => array("whois.ripn.ru","whois.ripn.net"),
"ro" => array("whois.rotld.ro"),
"aero" => array("whois.aero"),
"fr" => array("whois.nic.fr"),
"se" => array("whois.iis.se","whois.nic-se.se","whois.nic.se"),
"nl" => array("whois.sidn.nl","whois.domain-registry.nl"),
"nz" => array("whois.srs.net.nz","whois.domainz.net.nz"),
"mx" => array("whois.nic.mx"),
"tw" => array("whois.apnic.net","whois.twnic.net.tw"),
"ch" => array("whois.nic.ch"),
"hk" => array("whois.hknic.net.hk"),
"ac" => array("whois.nic.ac"),
"ae" => array("whois.nic.ae"),
"af" => array("whois.nic.af"),
"ag" => array("whois.nic.ag"),
"al" => array("whois.ripe.net"),
"am" => array("whois.amnic.net"),
"as" => array("whois.nic.as"),
"az" => array("whois.ripe.net"),
"ba" => array("whois.ripe.net"),
"bg" => array("whois.register.bg"),
"bi" => array("whois.nic.bi"),
"bj" => array("www.nic.bj"),
"br" => array("whois.nic.br"),
"bt" => array("whois.netnames.net"),
"by" => array("whois.ripe.net"),
"bz" => array("whois.belizenic.bz"),
"cd" => array("whois.nic.cd"),
"ck" => array("whois.nic.ck"),
"cl" => array("nic.cl"),
"coop" => array("whois.nic.coop"),
"cx" => array("whois.nic.cx"),
"cy" => array("whois.ripe.net"),
"cz" => array("whois.nic.cz"),
"dk" => array("whois.dk-hostmaster.dk"),
"dm" => array("whois.nic.cx"),
"dz" => array("whois.ripe.net"),
"ee" => array("whois.eenet.ee"),
"eg" => array("whois.ripe.net"),
"es" => array("whois.ripe.net"),
"fi" => array("whois.ficora.fi"),
"fo" => array("whois.ripe.net"),
"gb" => array("whois.ripe.net"),
"ge" => array("whois.ripe.net"),
"gl" => array("whois.ripe.net"),
"gm" => array("whois.ripe.net"),
"gov" => array("whois.nic.gov"),
"gr" => array("whois.ripe.net"),
"gs" => array("whois.adamsnames.tc"),
"hm" => array("whois.registry.hm"),
"hn" => array("whois2.afilias-grs.net"),
"hr" => array("whois.ripe.net"),
"hu" => array("whois.ripe.net"),
"il" => array("whois.isoc.org.il"),
"int" => array("whois.isi.edu"),
"iq" => array("vrx.net"),
"ir" => array("whois.nic.ir"),
"is" => array("whois.isnic.is"),
"je" => array("whois.je"),
"jp" => array("whois.jprs.jp"),
"kg" => array("whois.domain.kg"),
"kr" => array("whois.nic.or.kr"),
"la" => array("whois2.afilias-grs.net"),
"lt" => array("whois.domreg.lt"),
"lu" => array("whois.restena.lu"),
"lv" => array("whois.nic.lv"),
"ly" => array("whois.lydomains.com"),
"ma" => array("whois.iam.net.ma"),
"mc" => array("whois.ripe.net"),
"md" => array("whois.nic.md"),
"mil" => array("whois.nic.mil"),
"mk" => array("whois.ripe.net"),
"ms" => array("whois.nic.ms"),
"mt" => array("whois.ripe.net"),
"mu" => array("whois.nic.mu"),
"my" => array("whois.mynic.net.my"),
"nf" => array("whois.nic.cx"),
"pl" => array("whois.dns.pl"),
"pr" => array("whois.nic.pr"),
"pt" => array("whois.dns.pt"),
"sa" => array("saudinic.net.sa"),
"sb" => array("whois.nic.net.sb"),
"sg" => array("whois.nic.net.sg"),
"sh" => array("whois.nic.sh"),
"si" => array("whois.arnes.si"),
"sk" => array("whois.sk-nic.sk"),
"sm" => array("whois.ripe.net"),
"st" => array("whois.nic.st"),
"su" => array("whois.ripn.net"),
"tc" => array("whois.adamsnames.tc"),
"tf" => array("whois.nic.tf"),
"th" => array("whois.thnic.net"),
"tj" => array("whois.nic.tj"),
"tk" => array("whois.nic.tk"),
"tl" => array("whois.domains.tl"),
"tm" => array("whois.nic.tm"),
"tn" => array("whois.ripe.net"),
"to" => array("whois.tonic.to"),
"tp" => array("whois.domains.tl"),
"tr" => array("whois.nic.tr"),
"ua" => array("whois.ripe.net"),
"uy" => array("nic.uy"),
"uz" => array("whois.cctld.uz"),
"va" => array("whois.ripe.net"),
"vc" => array("whois2.afilias-grs.net"),
"ve" => array("whois.nic.ve"),
"vg" => array("whois.adamsnames.tc"),
"yu" => array("whois.ripe.net")
);
public function whoislookup($domain)
{
$domain = trim($domain); //remove space from start and end of domain
if(substr(strtolower($domain), 0, 7) == "http://") $domain = substr($domain, 7); // remove http:// if included
if(substr(strtolower($domain), 0, 4) == "www.") $domain = substr($domain, 4);//remove www from domain
if(preg_match("/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/",$domain))
return $this->queryWhois("whois.lacnic.net",$domain);
elseif(preg_match("/^([-a-z0-9]{2,100})\.([a-z\.]{2,8})$/i",$domain))
{
$domain_parts = explode(".", $domain);
$tld = strtolower(array_pop($domain_parts));
$server = $this->WHOIS_SERVERS[$tld][0];
if(!$server) {
return "Error: No appropriate Whois server found for $domain domain!";
}
$res=$this->queryWhois($server,$domain);
while(preg_match_all("/Whois Server: (.*)/", $res, $matches))
{
$server=array_pop($matches[1]);
$res=$this->queryWhois($server,$domain);
}
return $res;
}
else
return "Invalid Input";
}
private function queryWhois($server,$domain)
{
$fp = @fsockopen($server, 43, $errno, $errstr, 20) or die("Socket Error " . $errno . " - " . $errstr);
if($server=="whois.verisign-grs.com")
$domain="=".$domain;
fputs($fp, $domain . "\r\n");
$out = "";
while(!feof($fp)){
$out .= fgets($fp);
}
fclose($fp);
return $out;
}
}
?>

调用的方式

<?php
require("whois.class.php");
$whois=new Whois;
echo $whois->whoislookup("3water.com");
?>

运行结果:

Domain Name: JB51.NET Registry Domain ID: 527217184_DOMAIN_NET-VRSN Registrar WHOIS Server: whois.godaddy.com Registrar URL: http://www.godaddy.com Updated Date: 2016-05-26T08:17:44Z Creation Date: 2006-07-22T03:11:39Z Registry Expiry Date: 2024-07-22T03:11:39Z Registrar: GoDaddy.com, LLC Registrar IANA ID: 146 Registrar Abuse Contact Email: abuse@godaddy.com Registrar Abuse Contact Phone: 480-624-2505 Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited Domain Status: clientRenewProhibited https://icann.org/epp#clientRenewProhibited Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited Name Server: NS1.DNSV2.COM Name Server: NS2.DNSV2.COM DNSSEC: unsigned URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/ >>> Last update of whois database: 2019-04-03T03:32:17Z <<< For more information on Whois status codes, please visit https://icann.org/epp NOTICE: The expiration date displayed in this record is the date the registrar's sponsorship of the domain name registration in the registry is currently set to expire. This date does not necessarily reflect the expiration date of the domain name registrant's agreement with the sponsoring registrar. Users may consult the sponsoring registrar's Whois database to view the registrar's reported date of expiration for this registration. TERMS OF USE: You are not authorized to access or query our Whois database through the use of electronic processes that are high-volume and automated except as reasonably necessary to register domain names or modify existing registrations; the Data in VeriSign Global Registry Services' ("VeriSign") Whois database is provided by VeriSign for information purposes only, and to assist persons in obtaining information about or related to a domain name registration record. VeriSign does not guarantee its accuracy. By submitting a Whois query, you agree to abide by the following terms of use: You agree that you may use this Data only for lawful purposes and that under no circumstances will you use this Data to: (1) allow, enable, or otherwise support the transmission of mass unsolicited, commercial advertising or solicitations via e-mail, telephone, or facsimile; or (2) enable high volume, automated, electronic processes that apply to VeriSign (or its computer systems). The compilation, repackaging, dissemination or other use of this Data is expressly prohibited without the prior written consent of VeriSign. You agree not to use electronic processes that are automated and high-volume to access or query the Whois database except as reasonably necessary to register domain names or modify existing registrations. VeriSign reserves the right to restrict your access to the Whois database in its sole discretion to ensure operational stability. VeriSign may restrict or terminate your access to the Whois database for failure to abide by these terms of use. VeriSign reserves the right to modify these terms at any time. The Registry database contains ONLY .COM, .NET, .EDU domains and Registrars.

希望本文所述对大家PHP程序设计有所帮助。

PHP 相关文章推荐
PHP 高级课程笔记 面向对象
Jun 21 PHP
php检测图片木马多进制编程实践
Apr 11 PHP
解决File size limit exceeded 错误的方法
Jun 14 PHP
php中获取主机名、协议及IP地址的方法
Nov 18 PHP
JavaScript实现滚动栏效果的方法
Apr 27 PHP
php中JSON的使用方法
Apr 30 PHP
php简单实现数组分页的方法
Apr 30 PHP
php获取网站根目录物理路径的几种方法(推荐)
Mar 04 PHP
PHP Include文件实例讲解
Feb 15 PHP
利用PHP如何统计Nginx日志的User Agent数据
Mar 06 PHP
Laravel 关联模型-关联新增和关联更新的方法
Oct 10 PHP
PHP发送邮件确认验证注册功能示例【修改别人邮件类】
Nov 09 PHP
ThinkPHP3.2.3框架实现的空模块、空控制器、空操作,跳转到错误404页面图文详解
Apr 03 #PHP
PHP反射实际应用示例
Apr 03 #PHP
ThinkPHP3.2.3框架实现执行原生SQL语句的方法示例
Apr 03 #PHP
从ThinkPHP3.2.3过渡到ThinkPHP5.0学习笔记图文详解
Apr 03 #PHP
PHP快速排序算法实现的原理及代码详解
Apr 03 #PHP
Laravel5.7框架安装与使用学习笔记图文详解
Apr 02 #PHP
Laravel访问出错提示:`Warning: require(/vendor/autoload.php): failed to open stream: No such file or di解决方法
Apr 02 #PHP
You might like
电脑硬件及电脑配置知识大全
2020/03/17 数码科技
让你同时上传 1000 个文件 (一)
2006/10/09 PHP
ThinkPHP3.1新特性之G方法的使用
2014/06/19 PHP
yiic命令时提示“php.exe”不是内部或外部命令的解决方法
2014/12/18 PHP
php有效防止图片盗用、盗链的两种方法
2016/11/01 PHP
Yii2框架中日志的使用方法分析
2017/05/22 PHP
PHP设计模式(七)组合模式Composite实例详解【结构型】
2020/05/02 PHP
JS 文字符串转换unicode编码函数
2009/05/30 Javascript
JS运行耗时操作的延时显示方法
2010/11/19 Javascript
js动态修改表格行colspan列跨度的方法
2015/03/30 Javascript
深入分析下javascript中的[]()+!
2015/07/07 Javascript
学习Javascript闭包(Closure)知识
2016/08/07 Javascript
Vue.js绑定HTML class数组语法错误的原因分析
2016/10/19 Javascript
Node.js与Sails redis组件的使用教程
2017/02/14 Javascript
Windows安装Node.js报错:2503、2502的解决方法
2017/10/25 Javascript
微信小程序实现图片预览功能
2018/01/31 Javascript
JS正则表达式常见用法实例详解
2018/06/19 Javascript
webpack4.x打包过程详解
2018/07/18 Javascript
在小程序开发中使用npm的方法
2018/10/17 Javascript
Ajax获取node服务器数据的完整步骤
2020/09/20 Javascript
Python爬虫番外篇之Cookie和Session详解
2017/12/27 Python
django ModelForm修改显示缩略图 imagefield类型的实例
2019/07/28 Python
使用Nibabel库对nii格式图像的读写操作
2020/07/01 Python
Django web自定义通用权限控制实现方法
2020/11/24 Python
澳大利亚首屈一指的鞋类品牌:Tony Bianco
2018/03/13 全球购物
服装厂厂长职责
2013/12/16 职场文书
多媒体专业自我鉴定
2014/02/28 职场文书
矿泉水广告词
2014/03/20 职场文书
公司保密承诺书
2014/03/27 职场文书
《美丽的丹顶鹤》教学反思
2014/04/22 职场文书
教师群众路线教育实践活动学习笔记
2014/11/05 职场文书
营业员岗位职责
2015/02/11 职场文书
学校重阳节活动总结
2015/03/24 职场文书
python超详细实现完整学生成绩管理系统
2022/03/17 Python
springboot应用服务启动事件的监听实现
2022/04/06 Java/Android
ICOM R71E和R72E图文对比解说
2022/04/07 无线电