动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   PHP → 阅读文章

 WHOIS类的修改版

作者来源: 
阅读 数 343 人次 , 2006-3-29 4:10:00 


1、简化了代码。(其实就是去掉了一些用不着的变量的定义)
2、针对从internic检索到的信息过于简单,根据internic反馈的信息中的whois server进行进一步查询。比如,yahoo在whois.networksolutions.com上有更详细的信息。

<?
class whois {

var $use_cache = 1;
var $from_cache=0;
var $cache_dir = "./"; // 根据你的系统自己设置

var $port = 43;
var $maxlen = 100;

// 如果你想在连接失败后自动重试,
// 设置重试次数 $max_retries
var $max_retries = 0;
var $sleep_val = 1;
var $retry = 0;

var $found = 0; // 查询没有结果,次值为0
var $error = 0; // 查询过程中的出错次数
var $data_min = 8;  // 我们至少应该获得8个字节的数据
var $data_count = 0;

var $whois_server;
var $new_whois;
var $further_info = 0;


// 打开和whois server的socket连接
// 默认的是 whois.internic.net
function connect ($server) {
$this->retry=0;
while($this->retry <= $this->max_retries):
$ptr = fsockopen($server, $this->port);
if($ptr>0):
$this->error=0; // just in case we're on a retry
return($ptr);
else:
$this->error++;
$this->retry++;
sleep($this->sleep_val);
endif;
endwhile;
}

// 获取简单的查询结果,并以行为单位,放入数组
// 国际域名查询
function rawlookup ($query, $server) {

if(!$query):
return( "");
endif;

$ptr=$this->connect($server);

if($ptr):
if(!ereg($query, "\n$")):
$query .= "\n";
endif;
fputs($ptr, "$query");
$i=0;
$this->found=1;
while(!feof($ptr)):
$array[$i]=fgets($ptr,$this->maxlen);
$this->data_count+=strlen(chop($array[$i]));
if(eregi( "no match for", $array[$i]) || eregi ("no entries found", $array[$i])):
$this->found=0;
 elseif(eregi( "whois database is down",$array[$i])):
$this->error++;
 $this->found=0;
 elseif(eregi( "please wait a while and try again",$array[$i])):
$this->error++;
 $this->found=0;
break;
endif;
if(eregi("whois server:",$array[$i])):
$this->new_whois=trim(substr(trim($array[$i]),(strlen(trim($array[$i]))-13)*(-1)));
$this->further_info=1;
endif;
$i++;
endwhile;

fclose($ptr);

if($this->data_count>$this->data_min):
return($array);
else:
$this->error++;
endif;
else:
$this->error++;
endif;
}


// 国内域名查询
function cnrawlookup ($query, $server) {
if(!$query):
return( "");
endif;

$ptr=$this->connect($server);
if($ptr):
if(!ereg($query, "\n$")):
$query .= "\n";
endif;
fputs($ptr, "$query");
$i=0;
$this->found=1;
while(!feof($ptr)):
$array[$i]=fgets($ptr,$this->maxlen);
$this->data_count+=strlen(chop($array[$i]));
if(eregi( "no match for", $array[$i]) || eregi ("no entries found", $array[$i])):
$this->found=0;
 elseif(eregi( "whois database is down",$array[$i])):
$this->error++;
 $this->found=0;
 elseif(eregi( "please wait a while and try again",$array[$i])):
$this->error++;
 $this->found=0;
break;
endif;
$i++;
endwhile;
fclose($ptr);

if($this->data_count>$this->data_min):
return($array);
else:
$this->error++;
endif;
else:
$this->error++;
endif;
}
};



$mywhois=new whois();

$thisname=$servername.$domainname;
// 根据国内域名或国际域名选择whois server
if (ereg(".cn$",$thisname))
{
$mywhois->whois_server="whois.cnnic.net.cn";
$array=$mywhois->cnrawlookup($thisname,$mywhois->whois_server);
}
else
{
$mywhois->whois_server="whois.internic.net";
//$mywhois->whois_server="whois.networksolutions.com";
$array=$mywhois->rawlookup($thisname,$mywhois->whois_server);
}



echo "<h2 align=center>".$thisname."</h2>";
echo "<table>";
$x=0;
while ($x<count($array))
{
echo "<tr><td>$x</td>";
echo "<td>$array[$x]</td>";
$x++;
}
echo "</table>";

if (!ereg(".cn$",$thisname))
{
echo "<h2 align=center>furth infomation</h2>";
$array_further=$mywhois->rawlookup($thisname,$mywhois->new_whois);

echo "<table>";
$x=0;
while ($x<count($array_further))
{
echo "<tr><td>$x</td>";
echo "<td>$array_further[$x]</td>";
$x++;
}
echo "</table>";
}

?>

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:UltraEdit支持php文档特殊显示的配置
· 下一篇:简单的页面缓冲技术
· 使用GeoIP和PHP构建一个简单的MySQL地理数据库
· 一个个人网页自动化生成系统(3)
· COM Functions in PHP4 (Windows)
· mhash 哈稀函数库
· 文件系统基本操作类


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077