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

前端之家收集整理的这篇文章主要介绍了PHP域whois脚本不返回所有信息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我需要获取whois信息.我的功能正常,但没有返回“管理联系人,注册人联系人,管理联系人,技术联系人”信息.

但是当我在Mac上运行以下命令时,它会返回所有信息
“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,$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/137177.html

猜你在找的PHP相关文章