帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > PHP编程
一个实现Whois的类
作者:匿名 发布时间:2002-12-25 来源:代码实验室
这个Whois类中只有一个方法,通过这个方法可以对几乎所有的domain name进行查询,并将查询结果返回。但对于新的domain name例如:.tv,.info,.biz等还不支持。



代码如下:



<?

/***************************************************



* ?Sloppycode.net All rights reserved.

* This is a standard copyright header for all source code appearing

* at sloppycode.net. This application/class/script may be redistributed,

* as long as the above copyright remains intact.

* Comments to sloppycode@sloppycode.net

***************************************************/



/***************************************************

* @title Whois wrapper for most global TLDs

* @author C.Small

* @version 1.4 - Timeout and whois_server properties added.

* @version 1.3 - Temporary fix for .name,.pro domains

* @version 1.2 - Error catching for .tv domains

* @version 1.1 - Converted to php

* @version 1.0 - Perl version [http://www.sloppycode.net/sloppycode/Perl[CGI]/s29.html]

***************************************************/



Class Whois

{

var $whois_server;

var $timeout = 30;



function lookup($domain)

{

$result = "";

$parts = array();

$host = "";



// .tv don't allow access to their whois

if (strstr($domain,".tv"))

{

$result = "'.tv' domain names require you to have an account to do whois searches.";

// New domains fix (half work, half don't)

} elseif (strstr($domain,".name") || strstr($domain,".pro") >0){

$result = ".name,.pro require you to have an account to do whois searches.";

} else{

if (empty($this->whois_server))

{

$parts = explode(".",$domain);

$testhost = $parts[sizeof($parts)-1];

$whoisserver = $testhost . ".whois-servers.net";

$this->host = gethostbyname($whoisserver);

$this->host = gethostbyaddr($this->host);



if ($this->host == $testhost)

{

$this->host = "whois.internic.net";

}

flush();

}

$whoisSocket = fsockopen($this->host,43, $errno, $errstr, $this->timeout);



if ($whoisSocket)

{

fputs($whoisSocket, $domain."1512");

while (!feof($whoisSocket))

{

$result .= fgets($whoisSocket,128) . "<br>";

}

fclose($whoisSocket);

}

}

return $result;

}

}

?>



上面的代码中定义了一个方法:lookup($domain),下面的这段代码就是测试这个类的功能的。



<?

include("clsWhois.php");

$whois = new Whois();

echo $whois->lookup("code-labs.com");

?>

  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·如何定义一个session 数组?  (2005-03-12)
 ·用ASP实现一个真正的注册页面  (2005-03-12)
 ·一个简单聊天室的建立.(供学习参  (2005-03-12)
 ·怎样才能将query string从一个as  (2005-03-12)
 ·一个BBS的源代码(一)  (2005-03-12)
 ·一个BBS的源代码(二)  (2005-03-12)
 ·一个BBS的源代码(三)  (2005-03-12)
 ·一个BBS的源代码(四)  (2005-03-12)
 ·一个BBS的源代码(五)  (2005-03-12)
 ·一个BBS的源代码(六)  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·Windows下集成安装Apache,PHP,MYSQ
·Mysql注入:SQL Injection with MyS
·PHP 的来龙去脉
·PHP 的功能概述
·PHP与其它CGI的比较
·PHP 的编译配置详细选项
·php.ini 配置详细选项
·如何写作PHP程序
·Hello,World
·嵌入方法
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统