欢迎光临
我们一直在努力

WHOIS类的修改版。-PHP教程,PHP应用

建站超值云服务器,限时71元/月

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 were 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>";
}

?>  

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » WHOIS类的修改版。-PHP教程,PHP应用
分享到: 更多 (0)