php get domain whois

Discussion in 'PHP' started by tnd8, Nov 14, 2010.

  1. #1
    This code show whois information of a domain.
    
    $domain = 'digitalpoint.com';
    $whois = '';
    $connection = @fsockopen('whois.verisign-grs.com', 43);
    if ($connection) {
    	@fputs($connection, $domain ."\r\n");
    	while (!feof($connection)) {
    		$whois .= @fgets($connection, 128);
    	}
    }
    fclose($connection);
    echo $whois;
    
    PHP:
    but, when

    $domain = 'cnn.com';
    Code (markup):
    result:

    CNN.COM.MORE.INFO.AT.WWW.BEYONDWHOIS.COM
    CNN.COM.IS.0WN3D.BY.GULLI.COM
    CNN.COM

    Any one can give me a hint how to get the correct whois information of that domain (lie cnn.com). Many thanks.
     
    tnd8, Nov 14, 2010 IP
  2. d_s

    d_s Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    why don't you use the built-in whois command in the linux server. Here is a sample code
    
    <?php
    /**
     * @file ipdomains.php
     *
     * A simple WHOIS (wrapper) object written in PHP. Specially for the LINUX servers.
     *
     * @author Saravanan <doraiswamy.saravanan@gmail.com>
     *
     *
     */
    
    class whois
    {
        var $cmd;
    
        function whois()
        {
            $this->set_whois_cmd();
            return;
        }
        
        function set_whois_cmd()
        {
            if (file_exists('/usr/local/bin/whois'))
            {
                $this->cmd = '/usr/local/bin/whois';
            }
            elseif (file_exists('/usr/bin/whois'))
            {
                $this->cmd = '/usr/bin/whois';
            }
            elseif (file_exists('/bin/whois'))
            {
                $this->cmd = '/bin/whois';
            }
            else
            {
                die("<h1>Error:</h1>\n<p>Couldn't locate the 'whois' program.</p>");
            }
        }
        
        function query($domain) 
        {
            /**
             * return the whois results with text linebreaks converted into html linebreaks 
             */
            return nl2br(shell_exec(escapeshellcmd($this->cmd ." ". $domain)));
        }
    }
    
    $ob = new whois();
    echo $ob->query('google.com');
    ?> 
    
    Code (markup):
    regards,

    d_s
     
    d_s, Nov 15, 2010 IP
  3. tnd8

    tnd8 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank for your code, d_s
     
    tnd8, Nov 15, 2010 IP