PHP域whois脚本不返回所有信息

标签 php api command-line-interface whois

我需要获取 whois 信息。我的功能运行良好,但未返回“管理联系人、注册人联系人、管理联系人、技术联系人”信息。

但是当我在我的 Mac 上运行以下命令时,它会返回所有信息 “whois google.com”

这是我从 whois 服务器获取信息的 php 函数

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");

关于PHP域whois脚本不返回所有信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49803380/

相关文章:

php - RasPi上php5与mysql连接错误

javascript - 对数据库的 API 响应中的字符串进行编码或转义?

rest - 如何为NFL Shield API创建访问 token ?

PHP Time() 在 MySQL 中的存储

php - 在 PHP 中创建字母数字范围

php - Woocommerce REST API - 如果实时网站上的订单与其他网站上的产品不匹配,则跳过订单传输

java - 为什么 picocli 不能从命令行识别我的选项?

linux - 排除目录 mv unix

java - 默认的micronaut应用程序未运行

PHP/SQL 使用之前查询的数据查询另一个表