Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Getting started with a whois script.

Getting started with a whois script.

Getting started with a whois script.

I have been asked to write a whois script.  Does anyone have any pointers?  It will take a domain name without the TLD and then add a selected TLD and search for it.  Anyone got any ideas?

my test site

RE: Getting started with a whois script.

OK. Does anyone have any advice on the use of

$nslookup = "/user/bin/nslookup";
$command = "$nslookup -timeout=2 -q=ns $domainname 2>&1";
open(SHELL, "$command ¦");

What does it all mean?  I am stuggling here :)

my test site

RE: Getting started with a whois script.

nslookup - is a UNIX command to get information about boxes on a network, be it an intranet or the internet.  It sends queries to a domain name server to get information about the servers that the domain name server knows about.  There are a variety of arguments.  
The ones you are using, -timeout and domainname, do what they sound like.  
    -timeout specifies how long to try to get a response before dying.
    -domainname specifies the mask for the domain your are interested in.

So, we have a UNIX command and two args for it.

Next, what does open(SHELL, "$command ¦");  do?
Answer - the '¦' char in the end of the parens is called a pipe and is a pipe.  That is, the character is a pipe AND the syntax opens a 'pipe' to the UNIX command and attaches a handle to it.  That means you can read from the stuff the UNIX command spits back just like it is a file.

So, your code builds the appropriate syntax to use with the nslookup command and then opens a pipe to that command so you can catch what it spits back.

Hope this helps.......

RE: Getting started with a whois script.

Thanks goBoating.  It has helped.  The script is coming along nicely now.


my test site

RE: Getting started with a whois script.

$command = "$nslookup -timeout=2 -q=ns $domainname 2>&1";
OK, I have this down to check for an authoritative answer from some nameservers.  I cannot get it to return $nameservers = 1 though.  I have tried to match:

Authoritative Answer
Authoritative Answers
Authoritative answers

$nslookup = "/usr/local/bin/nslookup";
open(SHELL, "$command ¦");
while(<SHELL>) {
#looking for authoritative nameserver
if (/^Authoritative Answer/) {
$nameservers = 1;
$nameservers = 0;
print "$out\n";

Anyone got any ideas on this one?


my test site

RE: Getting started with a whois script.

a little more UNIX stuff.......
When you use the open(SHELL,"$command ¦"), the pipe connects to STDOUT of the command.  It looks like your command has redirected STDOUT to go to somewhere else.  If this is the case, then the output of nslookup will not make it back through the pipe.  The > is the redirect operator.

You can run nslookup from the command line.  Loose the >&1, run it at a prompt and see what you get back.  Make sure you are using the nslookup command the way your OS expects.  

I am using SunOS 5.6...when I do this...
nslookup -timeout=5 -q=ns awac.com
I get this....
Server:  someserver.somewhere.com

Non-authoritative answer:
awac.com nameserver = ns-1.awac.com
awac.com nameserver = ns-2.awac.com

Authoritative answers can be found from:
ns-1.awac.com internet address =
ns-2.awac.com internet address =

the names have been changed to protect the innocent

Once, you are sure you are using the command correctly, migrate the command syntax into your Perl code.  Drop a print in the 'while(SHELL,"$command ¦" { }' loop to make sure you are, in fact, getting something back.  If so, what does it look like....make adjustments to your match and you're there.

' Hope this helps.

keep the rudder amid ship and beware the odd typo

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close