|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
那么接下来,这就算学会啦?NO,NO,NO,还早呢,你至尽还没碰过OOP之类的吧?模板呢? 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>";
}
?>
也得学会了PHP。然后再学,见异思迁是最不可取的,狗熊掰玉米就是这个道理,如果经常中途放弃,只能是一无所获,还浪费了N多的时间和经历,得不偿失,最重要的是,你会被别人瞧不起。 |
|