Install Command Line Whois on Linux Server

If the Whois command, as demonstrated  below, doesn’t work from the command line, then you likely have to install the Whois library.

Install Whois from Command Line

  1. Open a command prompt and log in to your Linux server. I use Putty to do this.
  2. change to the super user. I used sudo su or su sudo but some servers may have slightly different commands for this. Google it if you are not sure and those commands don’t do the trick, or you could simply proceed all future commands with sudo if all else fails.
  3. From the command Prompt, type: yum install whois

Possible issues installing Linux Command Line Whois

WHen I installed I got an error message that said that the following:

Existing lock /var/run/yum.pid: another copy is running as pid 27256.
Another app is currently holding the yum lock; waiting for it to exit…
  The other application is: yum-updatesd-he
    Memory :  29 M RSS (328 MB VSZ)
    Started: Mon May 19 19:18:12 2014 – 13:54 ago
    State  : Running, pid: 27256

So I had to learn how to kill that process and try again. Simply type:

kill ####

where #### is replaced by the pid number noted in the error. In my case it was 2756 as you can see in the red error text above.

You may have to also try these commands from command prompt if it’s not working yet:

1) service yum-updatesd stop
2) chkconfig yum-updatesd off

Using Linux Command Line Whois

Once installed, Linux Whois commands are fairly easy to use. For example, if you wanted the whois data for the Jafty.com domain from the whois server, whois.serverplan.com, then use the following commands:

 whois -h whois.serverplan.com jafty.com
or

whois  jafty.com

Note the -h parameter in the first example above. Only use that if you have a specific need to specify the host of the whois server you want to query, otherwise, use the simpler second example of “whois domain.com” and you’ll be good.

Here are options you can use with the Whois command as well:

Options

-h HOST Connect to WHOIS database host HOST.
-H Suppress the display of legal disclaimers.
-p PORT When connecting, connect to network port PORT.
–verbose Operate verbosely.
–help Display a help message, and exit.

 

Whois Alternative, jWhois

You can also use the very similar jWhois library if whois doesn’t do the trick for you. Simply use the following command to install it instead and use it similarly:

yum -y install jwhois

This worked for me(jwhois) wen the above whois instructions Did Not.

Coding a PHP Whois App that uses the Whois Command

The following PHP code will work with either whois or jWhois out of the box:

<?php
//whois servers that got what we need:
//whois2.softlayer.com
//whois.webnames.ca
//whois.tppinternet.com
//whois.totalregistrations.com
//whois.softlayer.com
//whois.serverplan.com
//trying:
//whois.godaddy.com have a try with below email!!! use with current whis first then this
function whoEmail($curdomn){
$whoserver = ‘whois.softlayer.com’;//’whois.serverplan.com’;//’whois.webnames.ca’;
$comand = “whois -h $whoserver $curdomn”;
$output = shell_exec($comand);
echo “Output: $output<hr>”;
$outarra = explode(‘Registrant Email:’,$output);//key 1 is email plus xtra
$output2 = $outarra[1];
$outarra2 = explode(‘Registry’,$output2);//key 0 is email so trim it
$emailout = trim($outarra2[0]);
//echo “Email: $emailout<hr>”;
//echo “$curdomn produced:<pre>$output</pre><hr>”;
return $emailout;
}//end whoEmail function.

//test function:
$e = whoEmail(‘dirm.com’);
echo “Email: $e<br>”;

?>

Notice at the top of my PHP script there are commented out whois server URLs. Feel free to experiment because I found that all of the ones listed there work with different domains. You can add more as well and increase the apps functionality by adding more code of course.

Summary

While I did find information online regarding the whois library and how to installl and use it, I found that it did not work and had to use the second option on this page, the jWhois library, which worked fine. I also went on to show you how you can write a nifty PHP script to work with the whois command, whether you used whois or jwhois, it will work the same.

 

One Reply to “Install Command Line Whois on Linux Server”

  1. Wow that was strange. I just wrote an really long comment but after I clicked submit
    my comment didn’t appear. Grrrr… well I’m not writing all that over again. Regardless,
    just wanted to say wonderful blog!

    my bblog post mp3; Jamila,

Leave a Reply

Your email address will not be published. Required fields are marked *