Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A ruby script to create shorter whois output UNIX
If you have ever used the whois command from Terminal, you know how many lines of legal junk comes along with the few lines of useful information you wanted. It almost always requires me to grab the mouse and scroll up a page or two to reach the vital information, and that is annoyingly wasteful. So in my quest to reduce the clutter, I wrote this ruby script to deal with the output from .com, .net, .org, and unspecified domain extensions.

I apologize in advance to any real ruby programmers out there, as this is the first script I have ever written. As far as I can tell, it works, but I imagine it is pretty inelegant, and I'm sure someone could clean it up and improve upon it. For one thing, I am not sure it deals well with all the options that you can pass to whois, but for just looking up basic details, you don't need any options.

Here's a sample of the output using my improved version of whois:
$ whois
   Whois Server:
   Referral URL:
   Name Server: S.NS.VERIO.NET
   Name Server: D.NS.VERIO.NET
   EPP Status: clientUpdateProhibited
   EPP Status: clientTransferProhibited
   EPP Status: clientDeleteProhibited
   Updated Date: 27-Jun-2005
   Creation Date: 20-Nov-2001
   Expiration Date: 20-Nov-2006

 Last update of whois database: Sun, 10 Sep 2006 18:57:24 EDT
Compare that to the hundreds of lines you'll get from whois in Terminal, and you can see the space savings. To use the script, copy and paste the source into a new file in your favorite Terminal editor and save it as whois.rb. Make it executable (chmod 755 whois.rb), and you're ready to go. The easiest way to use it is probably via an alias; alias swhois='ruby /path/to/whois.rb. Then you can just type swhois, for instance, to use the abbreviated version.

[robg adds: When I tried this, I couldn't get the script to run if I just executed it via name (i.e. ./whois.rb). Even though the path to ruby is correct for my machine, the script only ran if I called it via ruby itself, as in the alias above. If you need the domain's address and email info from whois, you'll have to use the original command, as it's not included in this abbreviated output.]
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)

A ruby script to create shorter whois output | 5 comments | Create New Account
Click here to return to the 'A ruby script to create shorter whois output' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Need to clean out the \r's
Authored by: improbability on Sep 14, '06 08:26:19AM

The scripts has embedded ^m -- if you delete them
then ./whois.rb should work

tr -d '\r' < whois_rb.txt > whois.rb
chmod +x whois.rb

[ Reply to This | # ]
A ruby script to create shorter whois output
Authored by: Ganymede on Sep 14, '06 07:33:37PM

When I tried this, I got some error output - presumably from Ruby?
% ./whois.rb
./whois.rb:10: undefined method `extname' for File:Class (NameError)
Exit 1

Any Ideas?

[ Reply to This | # ]
A ruby script to create shorter whois output
Authored by: avanham on Sep 14, '06 09:26:26PM

Are you sure that it is being run by the ruby interpreter and not the bash interpreter? For some reason OSX doesn't always seem to respect the #!/usr/bin/ruby line and tries to execute the script as a bash script.

Try this:
ruby whois.rb

[ Reply to This | # ]
A ruby script to create shorter whois output
Authored by: esharef on Sep 15, '06 04:49:54AM
Note that you can get similarly good results if you just filter out lines with colon characters, using
 whois | grep : 
Maybe one or two unwanted lines slip through, but it does shorten the output a lot.

[ Reply to This | # ]
A ruby script to create shorter whois output
Authored by: MtnBiker on Jul 20, '07 10:59:02AM

Worked for me as described with two notes. I copied the script to TextMate from Safari and saved in my Scripts folder--can't see how any of this matters, but someone mentioned extraneous characters. Secondly I'm running ruby -v 1.8.6.

Thanks for the script and also publishing Ruby script which helps at least this Ruby newbie (or is that Ruby Nuby--groan).

Hermosa Beach, CA USA

[ Reply to This | # ]