coderholic

Whois Shell Script

I've got loads of little scripts that I've written lying around my hard drive. Some I've probably only used once and never looked at again, and others I use regularly. I thought I would post some of them here.

Here is a simple shell script that I wrote that performs a whois lookup of every domain name in a given file and outputs the registrant details:

#!/bin/bash
# usage: $0 <domains file>
domains=`cat $1`
for domain in $domains
do
    stripped_domain=${domain#www.} # strip a leading www.
    reg=`whois $stripped_domain | grep -i -A 1 registrant: | tail -n 1`
    echo "[$domain] $reg"
done

Given an input file containing the following domains

www.dowling.me.uk
www.google.com
www.wordpress.com
www.facebook.com

The script will output

[www.dowling.me.uk]     B. Dowling
[www.google.com]        Google Inc. (DOM-258879)
[www.wordpress.com]       Matt Mullenweg
[www.facebook.com]    Facebook, Inc

Obviously this is one of those scripts that I used once and never looked at again! :)

Posted on 08 Mar 2008
If you enjoyed reading this post you might want to follow @coderholic on twitter or browse though the full blog archive.