Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

Perl Shell Program for whois

Rated 4.08 (Ratings: 1) (Add your rating)

Log in to add a comment
(3 comments so far)

Want more?

 
Picture of AnthonyB

Anthony Baratta

Member info | Full bio

User since: July 09, 1999

Last login: October 25, 2006

Articles written: 12

Necessity maybe the mother of invention, but some times little 'side' projects can keep you from going crazy under tight deadlines. I've been beating my body silly the last two weeks to put together a e-commerce solution for one of my clients. Today was 'very' mentally draining with the 'final-final' review, edits, tweaks and 'oh-my-gawd-we-forgot-to...' going on.

During this 'hectic' time, I forced myself a few minutes here and there to divert my brain from the stress and wrote the following script. Believe it or not, the exercise really helped me stay focused on the important work.

Anyhoo - to make a long story longer, I was a little pissed off about the changes to rs.internic.net and the new 'limited' whois results. So I wrote the following Perl script to query rs.internic.net using the standard *NIX whois executable, capture the info - and if the domain existed, snag the whois server name from the info presented and offer you the option to query the responsible registrar for more detail on the domain.

I think its pretty slick. There might be a better way to do some of the things in the script, but output was more important than code elegance. Enjoy. Feedback is appreciated. Cut out the code between the demarcations below and watch out for line wrap. Save to a text file called 'ewhois' and place in your /home/username/bin directory. chmod to 755. To use, type 'ewhois domain.tld'. Note: I've found that there are some very handy extensions to the new internic whois (not mine). You can enter no extension (e.g. 'whois domain') and it will search all of the .com, .edu, .org and .net extensions for you - giving you a hit list of 'registered' domains. Also if you include no extension, but just the trailing '.' (e.g. 'whois domain.') it give you a hit list of all domains that _begin_ with the word entered.

#!/usr/bin/perl
##
## eWhois, an extended Whois Program
##
## Version .9b

## CopyLeft KeyBoard Jockeys, 1999
## www.keyboardjockeys.com
## eWhois@keyboardjockeys.com

## This program is NOT web browser safe!!
## There is no checking for 'funny' stuff.
## Do not use via a browser on an unsecure page.
 
## Just give the address you want
## to ewhois and if it exists in
## the rs.internic.net database,
## you'll be given the option to
## extend the search to the regitry
## who holds the source of the whois info
  
## edit the $varWhoisExe for your server
## put in your /home/username/bin directory
## chmod to 755
   
## usage: ewhois foo.edu
##        ewhois foo.
##        ewhois foo
   
## Edit this variable for your whois program
## Note some linux versions alias whois for fwhois
    $varWhoisExe = "/usr/bin/fwhois";
    #       $varWhoisExe = "/usr/bin/whois";

## Setting target of whois
     $varWhoisTarget = lc($ARGV[0]);
             
              ## If no arguments passed to program show help
              if ($varWhoisTarget) {
                   print "Processing...\n\n";
                   $varWhoisExe .= " " . $varWhoisTarget;
                   $varWhoisResultOne = `$varWhoisExe`;
                   print $varWhoisResultOne;
                   $varIndex = index(lc($varWhoisResultOne),"whois server:");
                   if ($varIndex > -1) {
                   	$varIndex1 = index(lc($varWhoisResultOne),"whois\.");
                          $varIndex2 = index(lc($varWhoisResultOne),"\.",($varIndex1+7));
                          $varLength = ($varIndex2 + 4) - $varIndex1; 
                          $varWhoisServer = substr($varWhoisResultOne,$varIndex1,$varLength);
                          $varWhoisExe .= "\@" . $varWhoisServer;
                          print "Query " . $varWhoisServer . " for more info on " . $varWhoisTarget . "? (y\/n) ";
                          chop($varAnswer=<STDIN>);
                          if (lc($varAnswer) eq "y") {
                                 print "\nProcessing...\n\n";
                                 $varWhoisResultTwo = `$varWhoisExe`;
                                 print $varWhoisResultTwo;
                          }
              }
              } else {
		  print "\nusage: ewhois domain.tld \n       ewhois domain.\n       ewhois domain\n";
	      }
	      exit;
Mutated into a life-size Dilbert doll, Anthony spends the days wedged into his replica of Cardinal Fang's Comfy Chair coding solutions to the most thorny of internet software problems.

Submitted by AnthonyB on January 19, 2000 - 03:40.

This code is now "living" at SourceForge.net. Feel free to visit the latest version there. http://sourceforge.net/snippet/detail.php?type=snippet&id=100034

login or register to post comments

Nice idea

Submitted by webspun on September 5, 2001 - 21:55.

Nice idea, but the script never queried the responsible registar. I simply got two incomplete whois reports. Plus, man did you make such an easy task so complicated. The script has sooooo much unnecessary code. I wrote a script to do the same thing. Look how much simpler it is and easier for people to read.

#!/usr/local/bin/perl
if(!@ARGV[0]){
print "Usage: mywhois <domainname>\n";
exit;
}
$domain=shift;
$registrar=`fwhois $domain\@whois.crsnic.net`;
$registrar =~ m/Whois Server: (.+)/;
$whois = $1;
print $registrar;
print "\nChecking $whois.....\n";
system("fwhois $domain\@$whois");

login or register to post comments

script bloc facebook IP

Submitted by smilovsky on January 26, 2012 - 10:26.

Hello everyone, I am looking for a shell or perl script to browse a log file, extract the IP, do a whois on each to see if IP address is a facebook or not if it's a facebook address, the script adds it to a file bloc_ip.txt if not it goes to the following address ... since I am not a developer, I want a loan or similar script that I can change it. Can someone help me?

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.