Create a one-step whois lookup script

Jan 29, '03 09:31:38AM

Contributed by: GEllenburg

OS X comes with the 'whois' command, a useful utility for checking domain name registrations and finding domain contacts. It's run from Terminal.app. However, since the advent of all the new ICANN approved registrars for domains, one must run 'whois' twice to actually get some meaningful results if the domain is not registered at Network Solutions. Run whois once to get the whois server that's serving the domain information, and a second time (with the "-h" swtich), to actually query the first referenced whois server.

I've written a little bash script to make this just a little bit easier (and in one step). It's included below in the hopes others may find it useful.

 #!/bin/bash
echo "Getting server..."
export SERVER=`whois $1 | grep -i whois\ server: |
awk '{print $3'}`
echo "Searching server: $SERVER"
whois -h $SERVER $1
[IMPORTAND NOTE: The "export" line must be entered as one line, not two; just replace the line break with a space...]

Copy the above text to your clipboard (Command+C), then fire off Terminal.app to create the script. Start a pico session, as root, and create the script with sudo pico /usr/bin/mywhois. Use Command+V to paste the above text into pico, and save and exit. Now, just make the script executable, by entering sudo chmod +x /usr/bin/mywhois, and you're done!

Now when you run a mywhois macosxhints.com, for example, the first few lines will show:
 Getting server...
Searching server: whois.godaddy.com
The data contained in Go Daddy Software, Inc.'s WHOIS database,
while believed by the company to be reliable, is provided "as is"...
[Editor's note: I tested this an it ran just fine as is in my relatively standard tcsh shell environment.]

Comments (17)


Mac OS X Hints
http://hints.macworld.com/article.php?story=200301290631382