有没有办法模拟“whois”? 使用php的工具?

发布于 2024-07-14 11:46:46 字数 148 浏览 7 评论 0原文

我的服务器上没有安装 whois(显然它正在开发中,但没有真正的新闻)。 我想知道是否有人知道一种模拟它的功能的方法。 我想我应该将一些数据发布到某个网址,但我不知道什么,也不知道在哪里。

基本上我完全不知所措,非常感谢任何帮助,甚至是我可以研究的东西。

I don't have whois installed on my server (apparently it's in the works but no real news on it). I was wondering if anybody knew a way to emulate the functionality of it though. I figured I'd be posting some data to a url but I don't know what, or where.

Basically I'm at a complete loss, and would appreciate any help or even something that I could look into.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

无声情话 2024-07-21 11:46:46

您可以使用 PHP Whois API。 这将允许您访问所有 whois 记录。 要使用该功能,该页面底部有一个指向类。 确保你也包括它。

You can use the PHP Whois API. This will allow you access to all the whois records. To use that function there is a link at the bottom of that page to a class. Make sure you include that too.

不醒的梦 2024-07-21 11:46:46

您可以尝试在您的系统上运行它,例如假设您使用的是 linux 并且安装了 /usr/bin/whois lib,那么您可以使用 php exec 运行 php

<?php exec("/usr/bin/whois $strDomain",$arrOutPut);?>

这仅在允许 php 使用 exec 函数时才有效在您的服务器上并确保验证传递给命令的参数...最终可能会使机器变得丑陋。

或者,您可以尝试使用 API

  1. http://www.nott.org/blog /php-whois-script.html
  2. http://www.tevine.com/projects /whois/

You can attempt to run it on your system, e.g. assuming you are using linux and you have the /usr/bin/whois lib installed then you can run php using the php exec

<?php exec("/usr/bin/whois $strDomain",$arrOutPut);?>

This will work only if php is allowed to use the exec function on your server and make sure to validate the arguments passed to the command...can end up ugly for the machine.

Alternatively you can try using an API

  1. http://www.nott.org/blog/php-whois-script.html
  2. http://www.tevine.com/projects/whois/
執念 2024-07-21 11:46:46

这是我不久前用一个简单的技巧写的 (无需列出所有 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>";

Here's one I've written a while ago using a simple trick (without listing out all the whois servers). I converted it from Perl, and it's also in C# and a COM object too.

It doesn't do all whois lookups as some of the domain registars are greedy *&!$ and want you to pay for the lookup, or keep it private. There's details about it on the page.

Update
Here's the code to save you downloading. I wrote it using PHP 3.x so some massaging for PHP5 might be needed:

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;
    }
}

Example usage

$whois = new Whois();
echo "<B>compaq.it</B><BR>";
echo $whois->lookup("compaq.it");
echo "<HR>";
夜唯美灬不弃 2024-07-21 11:46:46

您还可以使用 Net_Whois pear 包来实现此目的。

免责声明:我是这个包的维护者。

You could also utilise the Net_Whois pear package for this.

Disclaimer: I'm a maintainer of this package.

金橙橙 2024-07-21 11:46:46

看一下 RFC3912,它定义了 whois 协议。 基本上,您只需要在端口 43 上打开一个 TCP 套接字,在以 CR+LF 终止的一行上发送请求,然后从服务器读回一大块文本。

该标准(不幸的是)没有定义查询的格式,也没有定义回复的格式,也没有定义如何根据您需要执行的操作找到合适的 whois 服务器进行查询。

请查看我的其他回复以了解更多详细信息: https://unix.stackexchange.com/a/407030/ 211833

Have a look at RFC3912, it defines the whois protocol. Basically you just need to open a TCP socket on port 43, send your request on one line terminated by CR+LF and read back a blob of text from the server.

The standard (unfortunately) does not define the format of the query, nor of the reply, nor how to find the appropriate whois server to query based on what you need to do.

Please have a look at this other reply of me for more details: https://unix.stackexchange.com/a/407030/211833

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文