我没有在我的服务器上安装whois(显然它正在工作但没有真正的新闻)。我想知道是否有人知道如何模仿它的功能。我想我会将一些数据发布到网址,但我不知道是什么,或者在哪里。
基本上我完全失去了,并且会感激任何帮助甚至是我可以研究的东西。
你可以使用PHP Whois API。这将允许您访问所有whois记录。要使用该功能,该页面底部会有一个链接到a class。确保你也包含它。
您可以尝试在系统上运行它,例如假设您使用的是linux并且安装了/ usr / bin / whois lib,那么您可以使用php exec运行php
<?php exec("/usr/bin/whois $strDomain",$arrOutPut);?>
这只有在允许php使用服务器上的exec函数并确保验证传递给命令的参数时才会起作用...最终可能会对机器造成难看。
或者,您可以尝试使用API
Here's one I've written前一段时间使用了一个简单的技巧(没有列出所有的whois服务器)。我从Perl转换它,它也在C#和COM对象中。
它不会执行所有whois查找,因为某些域名注册表是贪婪的*&!$并且希望您为查找付费,或者将其保密。页面上有关于它的详细信息。
更新 这是保存下载的代码。我使用PHP 3.x编写它,因此可能需要对PHP5进行一些按摩:
class Whois
{
/*
* Optional parameter for the server to be used for the lookup.
* If this is not set, an appropriate whois server for the domain name
* specified is automagically found by the Whois class.
* @type string
* @access public
*/
var $whois_server;
/*
* The timeout, in seconds, for the lookup. Default is 30.
* @type integer
* @access public
*/
var $timeout = 30;
/*
* Returns a string, with new-lines (\n) converted to non-breaking spaces (<BR>),
* with details for the domain specified by $domain.
* @access public
* @param string $domain the domain to lookup, excluding http:// and www
* @return string the results of the whois
*/
function lookup($domain)
{
$result = "";
$parts = array();
$host = "";
// .tv don't allow access to their whois
if (strstr($domain,".tv"))
{
$result = "'.tv' domain names require you to have an account to do whois searches.";
// New domains fix (half work, half don't)
} elseif (strstr($domain,".name") || strstr($domain,".pro") >0){
$result = ".name,.pro require you to have an account to do whois searches.";
} else{
if (empty($this->whois_server))
{
$parts = explode(".",$domain);
$testhost = $parts[sizeof($parts)-1];
$whoisserver = $testhost . ".whois-servers.net";
$this->host = gethostbyname($whoisserver);
$this->host = gethostbyaddr($this->host);
if ($this->host == $testhost)
{
$this->host = "whois.internic.net";
}
flush();
}
$whoisSocket = fsockopen($this->host,43, $errno, $errstr, $this->timeout);
if ($whoisSocket)
{
fputs($whoisSocket, $domain."\015\012");
while (!feof($whoisSocket))
{
$result .= fgets($whoisSocket,128) . "<br>";
}
fclose($whoisSocket);
}
}
return $result;
}
}
用法示例
$whois = new Whois();
echo "<B>compaq.it</B><BR>";
echo $whois->lookup("compaq.it");
echo "<HR>";
您也可以使用Net_Whois pear package。
免责声明:我是这个软件包的维护者。
看看RFC3912,它定义了whois
协议。基本上你只需要在端口43上打开TCP套接字,在CR + LF终止的一行上发送你的请求,并从服务器读回一串文本。
标准(遗憾的是)没有定义查询的格式,也没有定义回复,也没有定义如何根据您需要的内容查找相应的whois服务器。
有关详细信息,请查看我的其他回复:https://unix.stackexchange.com/a/407030/211833