Whois 服务器未返回结果?
嗨,我一直在弄乱我从网络上获得的 Whois 脚本,并且一直在弄乱变量和数组,试图找出为什么它不会返回 Google 和 Facebook 的 Whois 结果(我测试了 google,因为这个是显而易见的),然后在得知它与 Whois 垃圾邮件有关,并且人们添加了该脚本所拾取的 google.com 子域(Facebook 也发生同样的情况)后测试了 facebook...
在做完作业后,我设法得到了它返回所有结果的列表(通过删除脚本中将所需的“=”.$domain 添加到域变量的部分。
之后,返回所有结果,我了解到脚本正在获取 Whois 服务器第一个结果(即 google.com.with.added.spam.com),因此无法在与“google.com.with.added.spam.com”相同的 whois 服务器上找到“google.com”因此它返回空白。
为了修复它,我已经尝试了一切,从反转 preg_match_all 数组(以获取最后一个 whois 服务器)到编辑我能想到的所有变量。
任何帮助将不胜感激。
提前致谢!!!
现在是代码:
<?php
$domain = $_GET['domain'];
// For the full list of TLDs/Whois servers see http://www.iana.org/domains/root/db/ and http://www.whois365.com/en/listtld/
$whoisservers = array(
"ac" =>"whois.nic.ac",
"ae" =>"whois.nic.ae",
"aero"=>"whois.aero",
"af" =>"whois.nic.af",
"ag" =>"whois.nic.ag",
"al" =>"whois.ripe.net",
"am" =>"whois.amnic.net",
"arpa" =>"whois.iana.org",
"as" =>"whois.nic.as",
"asia" =>"whois.nic.asia",
"at" =>"whois.nic.at",
"au" =>"whois.aunic.net",
"az" =>"whois.ripe.net",
"ba" =>"whois.ripe.net",
"be" =>"whois.dns.be",
"bg" =>"whois.register.bg",
"bi" =>"whois.nic.bi",
"biz" =>"whois.biz",
"bj" =>"whois.nic.bj",
"br" =>"whois.registro.br",
"bt" =>"whois.netnames.net",
"by" =>"whois.ripe.net",
"bz" =>"whois.belizenic.bz",
"ca" =>"whois.cira.ca",
"cat" =>"whois.cat",
"cc" =>"whois.nic.cc",
"cd" =>"whois.nic.cd",
"ch" =>"whois.nic.ch",
"ci" =>"whois.nic.ci",
"ck" =>"whois.nic.ck",
"cl" =>"whois.nic.cl",
"cn" =>"whois.cnnic.net.cn",
"com" =>"whois.verisign-grs.com",
"coop" =>"whois.nic.coop",
"cx" =>"whois.nic.cx",
"cy" =>"whois.ripe.net",
"cz" =>"whois.nic.cz",
"de" =>"whois.denic.de",
"dk" =>"whois.dk-hostmaster.dk",
"dm" =>"whois.nic.cx",
"dz" =>"whois.ripe.net",
"edu" =>"whois.educause.edu",
"ee" =>"whois.eenet.ee",
"eg" =>"whois.ripe.net",
"es" =>"whois.ripe.net",
"eu" =>"whois.eu",
"fi" =>"whois.ficora.fi",
"fo" =>"whois.ripe.net",
"fr" =>"whois.nic.fr",
"gb" =>"whois.ripe.net",
"gd" =>"whois.adamsnames.com",
"ge" =>"whois.ripe.net",
"gg" =>"whois.channelisles.net",
"gi" =>"whois2.afilias-grs.net",
"gl" =>"whois.ripe.net",
"gm" =>"whois.ripe.net",
"gov" =>"whois.nic.gov",
"gr" =>"whois.ripe.net",
"gs" =>"whois.nic.gs",
"gw" =>"whois.nic.gw",
"gy" =>"whois.registry.gy",
"hk" =>"whois.hkirc.hk",
"hm" =>"whois.registry.hm",
"hn" =>"whois2.afilias-grs.net",
"hr" =>"whois.ripe.net",
"hu" =>"whois.nic.hu",
"ie" =>"whois.domainregistry.ie",
"il" =>"whois.isoc.org.il",
"in" =>"whois.inregistry.net",
"info" =>"whois.afilias.net",
"int" =>"whois.iana.org",
"io" =>"whois.nic.io",
"iq" =>"vrx.net",
"ir" =>"whois.nic.ir",
"is" =>"whois.isnic.is",
"it" =>"whois.nic.it",
"je" =>"whois.channelisles.net",
"jobs" =>"jobswhois.verisign-grs.com",
"jp" =>"whois.jprs.jp",
"ke" =>"whois.kenic.or.ke",
"kg" =>"www.domain.kg",
"ki" =>"whois.nic.ki",
"kr" =>"whois.nic.or.kr",
"kz" =>"whois.nic.kz",
"la" =>"whois.nic.la",
"li" =>"whois.nic.li",
"lt" =>"whois.domreg.lt",
"lu" =>"whois.dns.lu",
"lv" =>"whois.nic.lv",
"ly" =>"whois.nic.ly",
"ma" =>"whois.iam.net.ma",
"mc" =>"whois.ripe.net",
"md" =>"whois.ripe.net",
"me" =>"whois.meregistry.net",
"mg" =>"whois.nic.mg",
"mil" =>"whois.nic.mil",
"mn" =>"whois.nic.mn",
"mobi" =>"whois.dotmobiregistry.net",
"ms" =>"whois.adamsnames.tc",
"mt" =>"whois.ripe.net",
"mu" =>"whois.nic.mu",
"museum" =>"whois.museum",
"mx" =>"whois.nic.mx",
"my" =>"whois.mynic.net.my",
"na" =>"whois.na-nic.com.na",
"name" =>"whois.nic.name",
"net" =>"whois.verisign-grs.net",
"nf" =>"whois.nic.nf",
"nl" =>"whois.domain-registry.nl",
"no" =>"whois.norid.no",
"nu" =>"whois.nic.nu",
"nz" =>"whois.srs.net.nz",
"org" =>"whois.pir.org",
"pl" =>"whois.dns.pl",
"pm" =>"whois.nic.pm",
"pr" =>"whois.uprr.pr",
"pro" =>"whois.registrypro.pro",
"pt" =>"whois.dns.pt",
"re" =>"whois.nic.re",
"ro" =>"whois.rotld.ro",
"ru" =>"whois.ripn.net",
"sa" =>"whois.nic.net.sa",
"sb" =>"whois.nic.net.sb",
"sc" =>"whois2.afilias-grs.net",
"se" =>"whois.iis.se",
"sg" =>"whois.nic.net.sg",
"sh" =>"whois.nic.sh",
"si" =>"whois.arnes.si",
"sk" =>"whois.ripe.net",
"sm" =>"whois.ripe.net",
"st" =>"whois.nic.st",
"su" =>"whois.ripn.net",
"tc" =>"whois.adamsnames.tc",
"tel" =>"whois.nic.tel",
"tf" =>"whois.nic.tf",
"th" =>"whois.thnic.net",
"tj" =>"whois.nic.tj",
"tk" =>"whois.dot.tk",
"tl" =>"whois.nic.tl",
"tm" =>"whois.nic.tm",
"tn" =>"whois.ripe.net",
"to" =>"whois.tonic.to",
"tp" =>"whois.nic.tl",
"tr" =>"whois.nic.tr",
"travel" =>"whois.nic.travel",
"tv" => "tvwhois.verisign-grs.com",
"tw" =>"whois.twnic.net.tw",
"ua" =>"whois.net.ua",
"ug" =>"whois.co.ug",
"uk" =>"whois.nic.uk",
"us" =>"whois.nic.us",
"uy" =>"nic.uy",
"uz" =>"whois.cctld.uz",
"va" =>"whois.ripe.net",
"vc" =>"whois2.afilias-grs.net",
"ve" =>"whois.nic.ve",
"vg" =>"whois.adamsnames.tc",
"wf" =>"whois.nic.wf",
"ws" =>"whois.website.ws",
"yt" =>"whois.nic.yt",
"yu" =>"whois.ripe.net");
function LookupDomain($domain){
global $whoisservers;
$domain_parts = explode(".", $domain);
$tld = strtolower(array_pop($domain_parts));
$whoisserver = $whoisservers[$tld];
if(!$whoisserver) {
return "Error: No appropriate Whois server found for $domain domain!";
}
$result = QueryWhoisServer($whoisserver, $domain);
if(!$result) {
return "Error: No results retrieved from $whoisserver server for $domain domain!";
}
else {
while(strpos($result, "Whois Server:") !== FALSE){
preg_match("/Whois Server: (.*)/", $result, $matches);
$secondary = $matches[1];
if($secondary) {
$result = QueryWhoisServer($secondary, $domain);
$whoisserver = $secondary;
}
}
}
return "$domain domain lookup results from $whoisserver server:\n\n" . $result;
}
function LookupIP($ip) {
$whoisservers = array(
//"whois.afrinic.net", // Africa - returns timeout error :-(
"whois.lacnic.net", // Latin America and Caribbean - returns data for ALL locations worldwide :-)
"whois.apnic.net", // Asia/Pacific only
"whois.arin.net", // North America only
"whois.ripe.net" // Europe, Middle East and Central Asia only
);
$results = array();
foreach($whoisservers as $whoisserver) {
$result = QueryWhoisServer($whoisserver, $ip);
if($result && !in_array($result, $results)) {
$results[$whoisserver]= $result;
}
}
$res = "RESULTS FOUND: " . count($results);
foreach($results as $whoisserver=>$result) {
$res .= "\n\n-------------\nLookup results for $ip from $whoisserver server:\n\n$result";
}
return $res;
}
function ValidateIP($ip) {
$ipnums = explode(".", $ip);
if(count($ipnums) != 4) {
return false;
}
foreach($ipnums as $ipnum) {
if(!is_numeric($ipnum) || ($ipnum > 255)) {
return false;
}
}
return $ip;
}
function ValidateDomain($domain) {
if(!preg_match("/^([-a-z0-9]{2,100})\.([a-z\.]{2,8})$/i", $domain)) {
return false;
}
return $domain;
}
function QueryWhoisServer($whoisserver, $domain) {
$port = 43;
$timeout = 10;
$fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
if($whoisserver == "whois.verisign-grs.com") $domain = "=".$domain; // whois.verisign-grs.com requires the equals sign ("=") or it returns any result containing the searched string.
fputs($fp, $domain . "\r\n");
$out = "";
while(!feof($fp)){
$out .= fgets($fp);
}
fclose($fp);
$res = "";
if((strpos(strtolower($out), "error") === FALSE) && (strpos(strtolower($out), "not allocated") === FALSE)) {
$rows = explode("\n", $out);
foreach($rows as $row) {
$row = trim($row);
if(($row != '') && ($row{0} != '#') && ($row{0} != '%')) {
$res .= $row."\n";
}
}
}
return $res;
}
?>
<html>
<head>
<title>Whois Lookup Script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF'];?>">
<p><b><label for="domain">Domain/IP Address:</label></b> <input type="text" name="domain" id="domain" value="<?=$domain;?>"> <input type="submit" value="Lookup"></p>
</form>
<?
if($domain) {
$domain = trim($domain);
if(substr(strtolower($domain), 0, 7) == "http://") $domain = substr($domain, 7);
if(substr(strtolower($domain), 0, 4) == "www.") $domain = substr($domain, 4);
if(ValidateIP($domain)) {
$result = LookupIP($domain);
}
elseif(ValidateDomain($domain)) {
$result = LookupDomain($domain);
}
else die("Invalid Input!");
echo "<pre>\n" . $result . "\n</pre>\n";
}
?>
</body>
</html>
Hi I have been messing with this Whois script I got of the 'net, and have been messing with variables and arrays for ever trying to figure out why it won't return the whois results for Google and Facebook (i tested google, as this is the obvious one), then tested facebook after learning it is to do with Whois spamming, and people adding google.com subdomains which this script picks up on (the same happens with facebook)...
After doing my homework i managed to get it to return a list of all results (by removing the section of the script that adds the required "=".$domain to the domain variable.
After that, all results were returned, and i learned the script was picking up the Whois server of the first result (which is a google.com.with.added.spam.com) and therefore "google.com" could not be found on the same whois server as "google.com.with.added.spam.com" therefore it is returning blank.
As to fix it I have tried everything from reversing the preg_match_all array (to grab the last whois server) to editing all the variables i can think of..
Any help would be greatly appreciated.
Thanks in advance!!!
And now the code:
<?php
$domain = $_GET['domain'];
// For the full list of TLDs/Whois servers see http://www.iana.org/domains/root/db/ and http://www.whois365.com/en/listtld/
$whoisservers = array(
"ac" =>"whois.nic.ac",
"ae" =>"whois.nic.ae",
"aero"=>"whois.aero",
"af" =>"whois.nic.af",
"ag" =>"whois.nic.ag",
"al" =>"whois.ripe.net",
"am" =>"whois.amnic.net",
"arpa" =>"whois.iana.org",
"as" =>"whois.nic.as",
"asia" =>"whois.nic.asia",
"at" =>"whois.nic.at",
"au" =>"whois.aunic.net",
"az" =>"whois.ripe.net",
"ba" =>"whois.ripe.net",
"be" =>"whois.dns.be",
"bg" =>"whois.register.bg",
"bi" =>"whois.nic.bi",
"biz" =>"whois.biz",
"bj" =>"whois.nic.bj",
"br" =>"whois.registro.br",
"bt" =>"whois.netnames.net",
"by" =>"whois.ripe.net",
"bz" =>"whois.belizenic.bz",
"ca" =>"whois.cira.ca",
"cat" =>"whois.cat",
"cc" =>"whois.nic.cc",
"cd" =>"whois.nic.cd",
"ch" =>"whois.nic.ch",
"ci" =>"whois.nic.ci",
"ck" =>"whois.nic.ck",
"cl" =>"whois.nic.cl",
"cn" =>"whois.cnnic.net.cn",
"com" =>"whois.verisign-grs.com",
"coop" =>"whois.nic.coop",
"cx" =>"whois.nic.cx",
"cy" =>"whois.ripe.net",
"cz" =>"whois.nic.cz",
"de" =>"whois.denic.de",
"dk" =>"whois.dk-hostmaster.dk",
"dm" =>"whois.nic.cx",
"dz" =>"whois.ripe.net",
"edu" =>"whois.educause.edu",
"ee" =>"whois.eenet.ee",
"eg" =>"whois.ripe.net",
"es" =>"whois.ripe.net",
"eu" =>"whois.eu",
"fi" =>"whois.ficora.fi",
"fo" =>"whois.ripe.net",
"fr" =>"whois.nic.fr",
"gb" =>"whois.ripe.net",
"gd" =>"whois.adamsnames.com",
"ge" =>"whois.ripe.net",
"gg" =>"whois.channelisles.net",
"gi" =>"whois2.afilias-grs.net",
"gl" =>"whois.ripe.net",
"gm" =>"whois.ripe.net",
"gov" =>"whois.nic.gov",
"gr" =>"whois.ripe.net",
"gs" =>"whois.nic.gs",
"gw" =>"whois.nic.gw",
"gy" =>"whois.registry.gy",
"hk" =>"whois.hkirc.hk",
"hm" =>"whois.registry.hm",
"hn" =>"whois2.afilias-grs.net",
"hr" =>"whois.ripe.net",
"hu" =>"whois.nic.hu",
"ie" =>"whois.domainregistry.ie",
"il" =>"whois.isoc.org.il",
"in" =>"whois.inregistry.net",
"info" =>"whois.afilias.net",
"int" =>"whois.iana.org",
"io" =>"whois.nic.io",
"iq" =>"vrx.net",
"ir" =>"whois.nic.ir",
"is" =>"whois.isnic.is",
"it" =>"whois.nic.it",
"je" =>"whois.channelisles.net",
"jobs" =>"jobswhois.verisign-grs.com",
"jp" =>"whois.jprs.jp",
"ke" =>"whois.kenic.or.ke",
"kg" =>"www.domain.kg",
"ki" =>"whois.nic.ki",
"kr" =>"whois.nic.or.kr",
"kz" =>"whois.nic.kz",
"la" =>"whois.nic.la",
"li" =>"whois.nic.li",
"lt" =>"whois.domreg.lt",
"lu" =>"whois.dns.lu",
"lv" =>"whois.nic.lv",
"ly" =>"whois.nic.ly",
"ma" =>"whois.iam.net.ma",
"mc" =>"whois.ripe.net",
"md" =>"whois.ripe.net",
"me" =>"whois.meregistry.net",
"mg" =>"whois.nic.mg",
"mil" =>"whois.nic.mil",
"mn" =>"whois.nic.mn",
"mobi" =>"whois.dotmobiregistry.net",
"ms" =>"whois.adamsnames.tc",
"mt" =>"whois.ripe.net",
"mu" =>"whois.nic.mu",
"museum" =>"whois.museum",
"mx" =>"whois.nic.mx",
"my" =>"whois.mynic.net.my",
"na" =>"whois.na-nic.com.na",
"name" =>"whois.nic.name",
"net" =>"whois.verisign-grs.net",
"nf" =>"whois.nic.nf",
"nl" =>"whois.domain-registry.nl",
"no" =>"whois.norid.no",
"nu" =>"whois.nic.nu",
"nz" =>"whois.srs.net.nz",
"org" =>"whois.pir.org",
"pl" =>"whois.dns.pl",
"pm" =>"whois.nic.pm",
"pr" =>"whois.uprr.pr",
"pro" =>"whois.registrypro.pro",
"pt" =>"whois.dns.pt",
"re" =>"whois.nic.re",
"ro" =>"whois.rotld.ro",
"ru" =>"whois.ripn.net",
"sa" =>"whois.nic.net.sa",
"sb" =>"whois.nic.net.sb",
"sc" =>"whois2.afilias-grs.net",
"se" =>"whois.iis.se",
"sg" =>"whois.nic.net.sg",
"sh" =>"whois.nic.sh",
"si" =>"whois.arnes.si",
"sk" =>"whois.ripe.net",
"sm" =>"whois.ripe.net",
"st" =>"whois.nic.st",
"su" =>"whois.ripn.net",
"tc" =>"whois.adamsnames.tc",
"tel" =>"whois.nic.tel",
"tf" =>"whois.nic.tf",
"th" =>"whois.thnic.net",
"tj" =>"whois.nic.tj",
"tk" =>"whois.dot.tk",
"tl" =>"whois.nic.tl",
"tm" =>"whois.nic.tm",
"tn" =>"whois.ripe.net",
"to" =>"whois.tonic.to",
"tp" =>"whois.nic.tl",
"tr" =>"whois.nic.tr",
"travel" =>"whois.nic.travel",
"tv" => "tvwhois.verisign-grs.com",
"tw" =>"whois.twnic.net.tw",
"ua" =>"whois.net.ua",
"ug" =>"whois.co.ug",
"uk" =>"whois.nic.uk",
"us" =>"whois.nic.us",
"uy" =>"nic.uy",
"uz" =>"whois.cctld.uz",
"va" =>"whois.ripe.net",
"vc" =>"whois2.afilias-grs.net",
"ve" =>"whois.nic.ve",
"vg" =>"whois.adamsnames.tc",
"wf" =>"whois.nic.wf",
"ws" =>"whois.website.ws",
"yt" =>"whois.nic.yt",
"yu" =>"whois.ripe.net");
function LookupDomain($domain){
global $whoisservers;
$domain_parts = explode(".", $domain);
$tld = strtolower(array_pop($domain_parts));
$whoisserver = $whoisservers[$tld];
if(!$whoisserver) {
return "Error: No appropriate Whois server found for $domain domain!";
}
$result = QueryWhoisServer($whoisserver, $domain);
if(!$result) {
return "Error: No results retrieved from $whoisserver server for $domain domain!";
}
else {
while(strpos($result, "Whois Server:") !== FALSE){
preg_match("/Whois Server: (.*)/", $result, $matches);
$secondary = $matches[1];
if($secondary) {
$result = QueryWhoisServer($secondary, $domain);
$whoisserver = $secondary;
}
}
}
return "$domain domain lookup results from $whoisserver server:\n\n" . $result;
}
function LookupIP($ip) {
$whoisservers = array(
//"whois.afrinic.net", // Africa - returns timeout error :-(
"whois.lacnic.net", // Latin America and Caribbean - returns data for ALL locations worldwide :-)
"whois.apnic.net", // Asia/Pacific only
"whois.arin.net", // North America only
"whois.ripe.net" // Europe, Middle East and Central Asia only
);
$results = array();
foreach($whoisservers as $whoisserver) {
$result = QueryWhoisServer($whoisserver, $ip);
if($result && !in_array($result, $results)) {
$results[$whoisserver]= $result;
}
}
$res = "RESULTS FOUND: " . count($results);
foreach($results as $whoisserver=>$result) {
$res .= "\n\n-------------\nLookup results for $ip from $whoisserver server:\n\n$result";
}
return $res;
}
function ValidateIP($ip) {
$ipnums = explode(".", $ip);
if(count($ipnums) != 4) {
return false;
}
foreach($ipnums as $ipnum) {
if(!is_numeric($ipnum) || ($ipnum > 255)) {
return false;
}
}
return $ip;
}
function ValidateDomain($domain) {
if(!preg_match("/^([-a-z0-9]{2,100})\.([a-z\.]{2,8})$/i", $domain)) {
return false;
}
return $domain;
}
function QueryWhoisServer($whoisserver, $domain) {
$port = 43;
$timeout = 10;
$fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
if($whoisserver == "whois.verisign-grs.com") $domain = "=".$domain; // whois.verisign-grs.com requires the equals sign ("=") or it returns any result containing the searched string.
fputs($fp, $domain . "\r\n");
$out = "";
while(!feof($fp)){
$out .= fgets($fp);
}
fclose($fp);
$res = "";
if((strpos(strtolower($out), "error") === FALSE) && (strpos(strtolower($out), "not allocated") === FALSE)) {
$rows = explode("\n", $out);
foreach($rows as $row) {
$row = trim($row);
if(($row != '') && ($row{0} != '#') && ($row{0} != '%')) {
$res .= $row."\n";
}
}
}
return $res;
}
?>
<html>
<head>
<title>Whois Lookup Script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<?=$_SERVER['PHP_SELF'];?>">
<p><b><label for="domain">Domain/IP Address:</label></b> <input type="text" name="domain" id="domain" value="<?=$domain;?>"> <input type="submit" value="Lookup"></p>
</form>
<?
if($domain) {
$domain = trim($domain);
if(substr(strtolower($domain), 0, 7) == "http://") $domain = substr($domain, 7);
if(substr(strtolower($domain), 0, 4) == "www.") $domain = substr($domain, 4);
if(ValidateIP($domain)) {
$result = LookupIP($domain);
}
elseif(ValidateDomain($domain)) {
$result = LookupDomain($domain);
}
else die("Invalid Input!");
echo "<pre>\n" . $result . "\n</pre>\n";
}
?>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您尝试从表单将域(例如:google.com)发送到脚本时,不要将其作为“google.com”发送,而是添加“域”一词,即(域 google.com)。
它的作用是告诉 whois 服务器查找该域(即 google.com),而不是任何其他包含 google 一词的域。
因此,在函数“LookupDomain($domain)”中,请确保 $domain 的值应该是
“domain google.com”以显示正确的结果。
When you are trying to send the domain(For example:google.com) to your script from the form, instead of sending it as 'google.com' add the word 'domain' i.e(domain google.com).
What this does, it tells the whois server to find this domain(i.e google.com) and not any other domain that has the word google in it.
So in the function "LookupDomain($domain)" be sure that the value of $domain should be
'domain google.com' for it to display the proper result.
将 .com 服务器更改为“whois.crsnic.net”,它应该可以工作
change the .com server to "whois.crsnic.net" and it should work
该脚本尚未运行。所以你可以尝试下面的代码
This script not working yet. so you can try the following code