WHOIS类的修改版
程序员文章站
2022-04-28 14:33:38
1、简化了代码。(其实就是去掉了一些用不着的变量的定义) 2、针对从internic检索到的信息过于简单,根据internic反馈的信息中的whois server进行进一...
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 "
".$thisname."
";
echo "";
$x=0;
while ($x {
echo " $x ";
echo " $array[$x] ";
$x++;
}
echo "
";
if (!ereg(".cn$",$thisname))
{
echo "
furth infomation
";
$array_further=$mywhois->rawlookup($thisname,$mywhois->new_whois);
echo "";
$x=0;
while ($x {
echo " $x ";
echo " $array_further[$x] ";
$x++;
}
echo "
";
}
?>
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 "
".$thisname."
";
echo "";
$x=0;
while ($x {
echo " $x ";
echo " $array[$x] ";
$x++;
}
echo "
";
if (!ereg(".cn$",$thisname))
{
echo "
furth infomation
";
$array_further=$mywhois->rawlookup($thisname,$mywhois->new_whois);
echo "";
$x=0;
while ($x {
echo " $x ";
echo " $array_further[$x] ";
$x++;
}
echo "
";
}
?>
上一篇: PHP 常用数据库操作
下一篇: git拉源码maven构建后部署脚本详解