5

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.

damnitshot
  • 249
  • 1
  • 4
  • 11

5 Answers5

5

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.

Sam Becker
  • 19,231
  • 14
  • 60
  • 80
3

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/
Ronald Conco
  • 855
  • 7
  • 11
  • This is the worst advice to give. Do not shell out just to run a simple whois command. Use the PHP libraries available for whois queries or just open a TCP socket on port 43 and read RFC3912 – Patrick Mevzek Jan 04 '18 at 21:23
1

You could also utilise the Net_Whois pear package for this.

Disclaimer: I'm a maintainer of this package.

kguest
  • 3,804
  • 3
  • 29
  • 31
1

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 (&lt;BR&gt;),
     * 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>";
Chris S
  • 64,770
  • 52
  • 221
  • 239
0

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

Community
  • 1
  • 1
Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54