PHP 域 whois 脚本没有 return 所有信息
PHP domain whois script not return all information
我需要获取 whois 信息。我的函数工作正常,但没有返回 "Administrative Contact, Registrant Contact, Administrative Contact, Technical Contact" 信息。
但是当我 运行 在我的 Mac 上执行命令时,它 returns 所有信息
"whois google.com"
这是我的 php 从 whois 服务器获取信息的函数
function QueryWhoisServer($whoisserver, $domain) {
$port = 43;
$timeout = 10;
$fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
fputs($fp, $domain . "\r\n");
$out = "";
while(!feof($fp)){
$out .= fgets($fp);
}
fclose($fp);
return $out;
}
echo QueryWhoisServer("whois.verisign-grs.com", "google.com");
我找到了一个可能的解决方案,假设(由我自己检查)注册商 whois 服务器正在返回联系信息。
为此,每个域都需要按照以下代码查询相关的注册商 whois 服务器。
查看代码注释,了解每个函数的作用。
function GetWhoisInfo($whoisserver, $domain){
$port = 43;
$timeout = 10;
$fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
stream_set_blocking($fp, true);
fputs($fp, $domain . "\r\n");
$out = "";
while(!feof($fp)){
$out .= fgets($fp);
}
fclose($fp);
return $out;
}
function GetRegistrarWhoisServer($whoisserver, $domain) {
$out = GetWhoisInfo($whoisserver, $domain);
$rws_string = explode("\r\n", $out);
$rws = explode("Registrar WHOIS Server: ", $rws_string[2])[1];
return $rws;
}
function WhoisToJson($winfo) {
$winfoarr = explode(PHP_EOL, $winfo);
$jsonarr = [];
foreach($winfoarr as $info){
$infodata = explode(": ", $info);
if($infodata[0] !== "")$jsonarr[$infodata[0]] = $infodata[1];
//avoid to process privacy info at the end of whois service output
if($infodata[0] === "DNSSEC")break;
}
return json_encode($jsonarr);
}
function QueryWhoisServer($whoisserver, $domain) {
//query to $whoisserver whois to get registrar whois server address only
$rws = GetRegistrarWhoisServer($whoisserver, $domain);
//query to registrar whois server (registrar whois servers are returning contact infos)
$out = GetWhoisInfo($rws, $domain);
//parsing infos and formatting to json
return WhoisToJson($out);
}
echo QueryWhoisServer("whois.verisign-grs.com", "google.com");
我需要获取 whois 信息。我的函数工作正常,但没有返回 "Administrative Contact, Registrant Contact, Administrative Contact, Technical Contact" 信息。
但是当我 运行 在我的 Mac 上执行命令时,它 returns 所有信息 "whois google.com"
这是我的 php 从 whois 服务器获取信息的函数
function QueryWhoisServer($whoisserver, $domain) {
$port = 43;
$timeout = 10;
$fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
fputs($fp, $domain . "\r\n");
$out = "";
while(!feof($fp)){
$out .= fgets($fp);
}
fclose($fp);
return $out;
}
echo QueryWhoisServer("whois.verisign-grs.com", "google.com");
我找到了一个可能的解决方案,假设(由我自己检查)注册商 whois 服务器正在返回联系信息。
为此,每个域都需要按照以下代码查询相关的注册商 whois 服务器。
查看代码注释,了解每个函数的作用。
function GetWhoisInfo($whoisserver, $domain){
$port = 43;
$timeout = 10;
$fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
stream_set_blocking($fp, true);
fputs($fp, $domain . "\r\n");
$out = "";
while(!feof($fp)){
$out .= fgets($fp);
}
fclose($fp);
return $out;
}
function GetRegistrarWhoisServer($whoisserver, $domain) {
$out = GetWhoisInfo($whoisserver, $domain);
$rws_string = explode("\r\n", $out);
$rws = explode("Registrar WHOIS Server: ", $rws_string[2])[1];
return $rws;
}
function WhoisToJson($winfo) {
$winfoarr = explode(PHP_EOL, $winfo);
$jsonarr = [];
foreach($winfoarr as $info){
$infodata = explode(": ", $info);
if($infodata[0] !== "")$jsonarr[$infodata[0]] = $infodata[1];
//avoid to process privacy info at the end of whois service output
if($infodata[0] === "DNSSEC")break;
}
return json_encode($jsonarr);
}
function QueryWhoisServer($whoisserver, $domain) {
//query to $whoisserver whois to get registrar whois server address only
$rws = GetRegistrarWhoisServer($whoisserver, $domain);
//query to registrar whois server (registrar whois servers are returning contact infos)
$out = GetWhoisInfo($rws, $domain);
//parsing infos and formatting to json
return WhoisToJson($out);
}
echo QueryWhoisServer("whois.verisign-grs.com", "google.com");